Ggraph node color to match edge color
Asked Answered
P

1

0

Is it possible to get ggraph to plot node colors the same color as connected edge color? I've tried feeding ggraph the colors for edges and nodes manually without any luck. It seems as if this would be something rather trivial, but I can't find any direction on it. My question is somewhat similar to this question, but I would like to color my nodes the same as their out-degree edges.

library(tidyverse)
library(igraph)
library(ggraph)


g <- graph_from_data_frame(highschool)


ggraph(g)+
  geom_edge_fan(aes(color = from))+
  geom_node_point(aes(color = name), show.legend = F, size = 5)

enter image description here

Phylloquinone answered 9/1, 2019 at 15:20 Comment(0)
S
2

This might work:

colfunc <- colorRampPalette(c("#00008B", "#63B8FF"))
cols <- colfunc(70)

ggraph(g)+
  geom_edge_fan(aes(color = from)) +
  scale_edge_colour_gradient(low = "#00008B", high = "#63B8FF") + 
  geom_node_point(color = cols, show.legend = F, size = 3)

enter image description here

Saari answered 9/1, 2019 at 15:38 Comment(1)
This is great, but how can you get it to match the colors above? Or, if you have preset the colors of the nodes in your layout, get edge color to match node colors to see connections?Inky

© 2022 - 2024 — McMap. All rights reserved.