如何在igraph中修改加权网络图

时间:2019-06-01 19:39:24

标签: r igraph weighted-graph

如何根据边缘权重对igraph中的加权网络图进行归一化处理?

1 个答案:

答案 0 :(得分:0)

igraph中,其中g是图形对象,您可以通过E(g)$weight访问边缘权重,并通过赋值E(g)$weight <- new_values来修改边缘权重。

要在0-1之间标准化,请尝试:E(g)$weight <- E(g)$weight / max(E(g)$weight)

这是一个可复制的示例,您可以复制和粘贴。

library(igraph)

set.seed(1) # reproducibility

# generate random graph
g <- sample_k_regular(10, k = 3, directed = FALSE, multiple = FALSE) 

# add edge weights
E(g)$weight <- sample(c(1,10,50), length(E(g)), replace = TRUE)

# view the problem
plot(g, edge.width = E(g)$weight)

enter image description here

# normalize the edge weights between 0-1
E(g)$weight <- E(g)$weight / max(E(g)$weight)

# play with different values of `k` until you get a reasonable looking graph
k = 9
plot(g, edge.width = E(g)$weight * k)

enter image description here