igraph根据权重绘制边线

igraph根据权重绘制边线

本文介绍了使用R igraph根据权重绘制边线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在R中绘制带有igraph的网络,其中边缘按权重排序.我已经分配了颜色,但是我想要背面的弱边缘和前面的强边缘.有没有办法做到这一点?谢谢

I'm trying to plot a network with igraph in R where the edges are sorted by weight. I have assigned colors, but I want weak edges on the back and strong edges in front. Is there a way of doing this?thanks

推荐答案

这是一个可能的解决方案.这实际上取决于您使用的是什么,因此使用代码示例可以改善这一点.

Here's a possible solution. It really depends on what you're working with, so with a code sample I could improve this.

基本上,边缘按出现的顺序绘制.因此,我们需要根据其权重属性对边缘进行排序.在同一张图中似乎不可能做到这一点,因此可能只需要创建一个具有相同属性但对边进行排序的新图即可.

Basically, edges are plotted in the order they appear. So we need to sort edges based on their weight attribute. This doesn't seem possible to do within the same graph, so it may just be necessary to create a new graph with the same attributes but with the edges sorted.

g <- graph( c(1,2, 1,3,1,4,1,5,2,3,2,4,2,5,3,4,3,5,4,5), n=5 )
E(g)$weight <- runif(10)

# Generates a the same graph but with edges sorted by weight.
h <- graph.empty() + vertices(V(g))
h <- h + edges(as.vector(t(get.edgelist(g)[order(E(g)$weight),])))
E(h)$weight <- E(g)$weight[order(E(g)$weight)]

E(h)$color <- "red"
E(h)[weight>0.3]$color <- "yellow"
E(h)[weight>0.7]$color <- "green"
plot(h,edge.width=2+3*E(h)$weight)

这篇关于使用R igraph根据权重绘制边线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 06:07