[英]Different aesthetic scales for different types of edges on same graph
I am trying to visualize some networks using the ggraph package.我正在尝试使用 ggraph 包可视化一些网络。 My network has two different types of edges, A and B, which have different scales.
我的网络有两种不同类型的边 A 和 B,它们具有不同的尺度。 I'd like to color the edges by type (which I've done) and also modulate their opacity by the value.
我想按类型(我已经完成)为边缘着色,并通过值调节它们的不透明度。 However, since all the edges are displayed together and since A and B have different scales, using
aes(alpha=value)
uses the entire scale over both A and B, so all the edges with the smaller scale (here A) are practically invisible.但是,由于所有边缘都显示在一起并且由于 A 和 B 具有不同的比例,因此使用
aes(alpha=value)
会在 A 和 B 上使用整个比例,因此所有具有较小比例的边缘(此处为 A)实际上是不可见的. How can I separate the alpha scales for A and B so that the alpha corresponds to their internal scales?如何分离 A 和 B 的 alpha 比例,以便 alpha 对应于它们的内部比例? (ie, alpha=1 when an A edge is at max A and a B edge is at max B)
(即,当 A 边缘位于最大 A 且 B 边缘位于最大 B 时,alpha=1)
I've included a small example below:我在下面包含了一个小示例:
library(ggplot2)
library(igraph)
library(ggraph)
nodes <- data.frame(id=seq(1,5),label=c('a','b','c','d','e'))
edges <- data.frame(from=c(3,3,4,1,5,3,4,5),
to= c(2,4,5,5,3,4,5,1),
type=c('A','A','A','A','A','B','B','B'),
value=c(1,.2,.5,.3,1,5,12,8))
net <- graph_from_data_frame(d=edges,vertices=nodes,directed=T)
ggraph(net,layout='stress') +
geom_edge_fan(aes(color=type,alpha=value)) +
geom_node_label(aes(label=label),size=5)
This is what the graph currently looks like:这是图表当前的样子:
And I want something that looks like this:我想要看起来像这样的东西:
Ideally I'd be able to do this in R and not do a convoluted editing process in GIMP.理想情况下,我可以在 R 中做到这一点,而不是在 GIMP 中进行复杂的编辑过程。
I was hoping this would be possible with set_scale_edge_alpha
, but I can't find the solution anywhere.我希望这可以通过
set_scale_edge_alpha
,但我无法在任何地方找到解决方案。 I saw from here that this can be done with ggnewscale
, but this seems to require drawing two separate objects, and it also doesn't seem like there is a function for specifically changing edge aesthetics.我从这里看到这可以用
ggnewscale
完成,但这似乎需要绘制两个单独的对象,而且似乎也没有专门改变边缘美学的功能。 Is there a simple way to do this without drawing two overlapping graphs?有没有一种简单的方法可以在不绘制两个重叠图的情况下做到这一点?
Thanks!谢谢!
It would probably be better just to rescale the values yourself before plotting.在绘图之前自己重新调整值可能会更好。 You can scale the values to a 0-1 scale within each group
您可以在每组中将值缩放到 0-1 的比例
edges <- edges %>%
group_by(type) %>%
mutate(value = scales::rescale(value))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.