Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何建立基于相关性的网络?_R_Networking - Fatal编程技术网

R 如何建立基于相关性的网络?

R 如何建立基于相关性的网络?,r,networking,R,Networking,我有一个矩阵如下 data <- replicate(30, rnorm(30)) 数据你的问题很不具体。但像这样的事情应该让你开始: # Generate some toy data data <- replicate(30, rnorm(30)) library("igraph") # Load the igraph package corr <- cor(data) # Create weighted adjencency/correlation matri

我有一个矩阵如下

data <- replicate(30, rnorm(30)) 

数据你的问题很不具体。但像这样的事情应该让你开始:

# Generate some toy data
data <- replicate(30, rnorm(30)) 

library("igraph")  # Load the igraph package

corr <- cor(data)  # Create weighted adjencency/correlation matrix

# Create a weighted complete graph from the correlation matrix
g <- graph.adjacency(corr, mode = "undirected", weighted = TRUE, diag = FALSE)

# Chose the layout function
custom.layout <- function(g, ...) {
  # layout.drl(g, weights = E(g)$weight, ...) # For bigger graphs
  layout.fruchterman.reingold(g, weights = E(g)$weight, ...)
}

现在它看起来不太像你展示的图表。首先,由于我们模拟玩具数据的方式,我们不期望有任何“中心”——一切都只是噪音。其次,布局高度依赖于布局功能。
第三,这只是为了让您了解如何定制图形和布局。

看看igraph软件包
# Format edges
E(g)$cor <- E(g)$weight
E(g)$weight <- abs(E(g)$cor)
E(g)$color <- ifelse(E(g)$cor < 0, "blue", "red")
E(g)$width <- 3*atanh(E(g)$weight)

# Format vertices
V(g)$size <- 3*abs(rowSums(corr))
V(g)$color <- "grey"
V(g)$label.color <- "black"
V(g)$label <- ""

# Do the plot
plot(g, layout = custom.layout)