简体   繁体   English

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

[英]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:这是图表当前的样子:

坏图.png

And I want something that looks like this:我想要看起来像这样的东西:

固定图.png

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.

相关问题 如何在不同的几何体中具有相同的美学(颜色)的不同尺度? - How to have different scales the same aesthetic (color) in different geoms? 使用填充美学两次,具有两种不同的比例 - Using fill aesthetic twice, with two different scales ggplot2中不同层的相同美学的不同色阶,没有不稳定的包装 - different color scales for same aesthetic in different layers in ggplot2, without unstable packages 在R中的同一图和同一轴上绘制两个比例不同的数据集 - Plot two datasets with different scales on the same graph, same axis in R 如何在 ggplot 中统一具有不同类型比例的图例? - How to unify a legend with different types of scales in ggplot? 根据不同的比例为图着色 - Coloring nodes of a graph according to the different scales 在 r 中的同一图表上绘制具有不同 x 轴百分比比例的 geom_col 和 geom_line - Plot geom_col and geom_line with different x-axis percentage scales on the same graph in r 在ggplot中移动具有相同美学但不同数据的图例条目的顺序 - Move order of legend entries of same aesthetic but different data in ggplot 如何在ggplot2中为相同的美学设置多个图例/比例? - How to set multiple legends / scales for the same aesthetic in ggplot2? 在X轴上具有不同比例的自定义R图 - Customized R Graph with Different scales in X-axis
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM