Ggraph node color to match edge color

2019-08-30 05:37发布

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

标签: r igraph ggraph
1条回答
何必那么认真
2楼-- · 2019-08-30 06:27

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

查看更多
登录 后发表回答