同一图上不同类型边缘的不同美学尺度
我正在尝试使用Ggraph软件包可视化一些网络。我的网络有两种不同类型的边缘A和B,它们具有不同的尺度。我想按类型(我已经完成)为边缘上色,并根据值调节它们的不透明度。但是,由于所有边缘都一起显示在一起,并且由于A和B具有不同的尺度,因此使用aes(alpha = value)
在A和B上都使用整个比例,因此所有具有较小比例的边缘(这里a)实际上是看不见的。如何将A和B的alpha量表分开,以使Alpha对应其内部尺度? (即,alpha = 1当a边缘在最大a处,b边缘在最大b)
我在下面包含一个小示例:
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)
这是图当前的样子:
,我想要看起来像这样的东西:
理想情况下,我可以在r中执行此操作,并且在gimp中不做令人费解的编辑过程。
我希望使用set_scale_edge_alpha
可以做到这一点,但是我在任何地方都找不到解决方案。我从在这里,这可以用ggnewscale ,但这似乎需要绘制两个单独的对象,而且似乎也没有一个专门更改边缘美学的函数。有没有简单的方法可以在不绘制两个重叠图的情况下进行操作?
谢谢!
I am trying to visualize some networks using the ggraph package. My network has two different types of edges, A and B, which have different scales. 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. How can I separate the alpha scales for A and B so that the alpha corresponds to their internal scales? (ie, alpha=1 when an A edge is at max A and a B edge is at max B)
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.
I was hoping this would be possible with set_scale_edge_alpha
, but I can't find the solution anywhere. 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. Is there a simple way to do this without drawing two overlapping graphs?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在绘制之前,自己重新销售价值观可能会更好。您可以将值扩展到每个组中的0-1比例
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