r - 标准化 igraph 中的边权重以进行绘图(边权重太厚)

标签 r igraph weighted-graph

如何根据边缘权重标准化 igraph 中边缘不太厚的加权网络图?

最佳答案

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

关于r - 标准化 igraph 中的边权重以进行绘图(边权重太厚),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56409878/

相关文章:

r - 创建具有固定边距的列联表

r - 根据包含参与者之间关系的数据框列更改边缘厚度

r - 在 R 中使用 igraph 创建正则图或邻接矩阵?

r - 如何在 R 中绘制无向连通图?

algorithm - 通过特定顶点的有向图中最轻量级的圆

r - 在 R 中使用复杂的调查设计提高查询速度

r - 将列表转换为字符串

r - 记住 Rcpp 函数?