我需要更改边缘的宽度,以对应于校正的权重:宽度1,相关性> 7,宽度2,相关性> 8,宽度3,相关性大于9
这是示例数据集
library(igraph)
set.seed(62)
N <- 7
fakecors <- runif(choose(N, 2))
cormat <- matrix(nrow = N, ncol = N)
cormat[lower.tri(cormat)] <- fakecors
diag(cormat) <- 0
cormat[upper.tri(cormat)] <- t(cormat)[upper.tri(t(cormat))]
matrixnetwork <- graph_from_adjacency_matrix(cormat, mode = "undirected", weighted = TRUE)
尝试这个表格: E(矩阵网络)$宽度 <- 3*E(matrixnetwork)$weight
E(matrixnetwork)[weight >= 0.7 & weight < 0]$width <- 2
E(matrixnetwork)[weight >= 0.8 & weight < 0.7]$width <- 4
E(matrixnetwork)[weight >= 0.9 & weight < 0.8]$width <- 8
E(matrixnetwork)$width <- ifelse(E(matrixnetwork)$weight >= 0.8, '3', '2')#configurar por espessura
E(matrixnetwork)$width <- ifelse(E(matrixnetwork)$weight >= 0.9, '5', '3')#configurar por espessura
E(matrixnetwork)$width <- ifelse(E(matrixnetwork)$weight >= 0.7, '1',
ifelse(E(matrixnetwork)$weight > 0.79, '3','1',
ifelse(E(matrixnetwork)$weight > 0.89, '5', '3')))
正确吗
library(igraph)
set.seed(62)
N <- 7
fakecors <- runif(choose(N, 2))
cormat <- matrix(nrow = N, ncol = N)
cormat[lower.tri(cormat)] <- fakecors
diag(cormat) <- 0
cormat[upper.tri(cormat)] <- t(cormat)[upper.tri(t(cormat))]
matrixnetwork <- graph_from_adjacency_matrix(cormat, mode = "undirected", weighted = TRUE)
# Set edge widths based on weight criteria
E(matrixnetwork)$width <- ifelse(E(matrixnetwork)$weight >= 0.9, 3, # width 3 for weight >= 0.9
ifelse(E(matrixnetwork)$weight >= 0.8, 2, # width 2 for weight >= 0.8
ifelse(E(matrixnetwork)$weight >= 0.7, 1, # width 1 for weight >= 0.7
0))) # Default width (0) for other cases
# Plot the network to visualize the edge widths
plot(matrixnetwork)