同一图上不同类型边缘的不同美学尺度

发布于 2025-02-13 12:47:02 字数 1411 浏览 0 评论 0原文

我正在尝试使用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:

badgraph.png

And I want something that looks like this:

fixedgraph.png

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风柔一江水 2025-02-20 12:47:02

在绘制之前,自己重新销售价值观可能会更好。您可以将值扩展到每个组中的0-1比例

edges <- edges %>% 
  group_by(type) %>% 
  mutate(value = scales::rescale(value))

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

edges <- edges %>% 
  group_by(type) %>% 
  mutate(value = scales::rescale(value))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文