如何根据边缘权重对igraph中的加权网络图进行归一化处理?
答案 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)
# 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)