Ggraph节点颜色与边缘颜色匹配 [英] Ggraph node color to match edge color

查看:113
本文介绍了Ggraph节点颜色与边缘颜色匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使ggraph绘制与连接的边缘颜色相同的颜色的节点颜色?我试过手动给ggraph填充边缘和节点的颜色,但没有任何运气.看来这似乎是微不足道的,但是我找不到任何方向.我的问题有点类似于此问题,但我想给节点涂上与他们的向外度边缘.

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)

推荐答案

这可能有效:

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)

这篇关于Ggraph节点颜色与边缘颜色匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆