Interpolating edge colors

Let’s make a graph artificially with tidygraph::play_gnp() and edit it.

Note use of .N$class[from] even when edges are activated.

graph <- tidygraph::play_gnp(n = 10, p = 0.2) %>% 
                    activate(nodes) %>% 
                    mutate(class = sample(letters[1:4], 
                                          n(), replace = TRUE)) %>% 
                    activate(edges) %>% 
                    arrange(.N()$class[from])

Interpolating colors between nodes:

ggraph(graph, layout = "stress") + 
  geom_edge_link2(
    aes(colour = node.class), 
    width = 3,
    lineend = "round")

“Edge geoms have access to the variables of the terminal nodes through specially prefixed variables.”