[英]Normalize edge weights in igraph for plotting (edge weights too thick)
如何根据边缘权重将边缘不太厚的igraph中的加权网络图标准化?
在igraph
, g
是图形对象,通过E(g)$weight
权重访问边缘权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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.