Ggraph node color to match edge color

一曲冷凌霜 提交于 2019-12-25 04:08:12

问题


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)


回答1:


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)



来源:https://stackoverflow.com/questions/54113284/ggraph-node-color-to-match-edge-color

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!