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

elliot
  • 1,844
  • 16
  • 45

1 Answers1

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

Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98
  • 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? – jebyrnes Apr 30 '19 at 17:35