gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 13:14:42 24 4
gpt4 key购买 nike

如何根据边缘权重对边缘不太厚的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com