R igraph Bipartite Graph,为什么我的体重没有显示?

时间:2017-02-21 23:18:25

标签: r igraph bipartite

我正在使用R和包igraph来创建基于关联矩阵的二分图,但我的权重没有显示?我添加了一个我想在下面尝试做的例子。我设置加权= TRUE,并期望边缘具有不同的权重,但线条的厚度都相同。关于我做错了什么的任何建议?

# Load packages
library(igraph)

# Create data
pNames <- paste("P", 1:4, sep="")
cNames <- paste("c", 1:3, sep="")
rData <- matrix(sample(4,12,replace=TRUE)-1,nrow=4,dimnames=list(pNames,cNames))
print(rData)

# Graph from matrix
b <- graph_from_incidence_matrix(rData,weighted=TRUE)

# Plot with layout
plot(b, layout=layout.bipartite,vertex.color=c("green","cyan")[V(b)$type+1],edge.width = b$weights)

1 个答案:

答案 0 :(得分:3)

您可以使用

找到边缘的属性
get.edge.attribute(b)
#$weight
#[1] 2 1 1 3 2 1 2

正如@paqmo所提到的,现在你知道了属性的名称,你可以用它来设置边缘宽度/标签:

plot(b, layout=layout.bipartite,vertex.color=c("green","cyan")[V(b)$type+1],
     edge.width = E(b)$weight, edge.label=E(b)$weight, edge.label.cex=2)

enter image description here