Load libraries and data

library(tidygraph)
library(ggraph)
# annotate highschool graph example
# as a tidygraph
data(highschool)
graph <- as_tbl_graph(highschool)

Plot the graph as is

graph %>%
  ggraph(layout="kk") +
  geom_edge_fan(arrow=arrow()) +
  geom_node_point() +
  theme_graph(foreground=NA)

Print the graph object

graph
# A tbl_graph: 70 nodes and 506 edges
#
# A directed multigraph with 1 component
#
# Node Data: 70 x 1 (active)
  name 
  <chr>
1 1    
2 2    
3 3    
4 4    
5 5    
6 6    
# ... with 64 more rows
#
# Edge Data: 506 x 3
   from    to  year
  <int> <int> <dbl>
1     1    13  1957
2     1    14  1957
3     1    20  1957
# ... with 503 more rows

Use edge color to indicate year

graph %>%
  ggraph(layout="kk") +
    geom_edge_fan(aes(color=factor(year)), arrow=arrow()) +
    geom_node_point() +
    theme_graph(foreground=NA)

Let’s only look at the 1958 subgraph

graph %>%
  activate(edges) %>%
  filter(year == 1958) %>%
  ggraph(layout="kk") +
    geom_edge_fan(aes(color=factor(year)), arrow=arrow()) +
    geom_node_point() +
    theme_graph(foreground=NA)