stefpeschel / NetCoMi

Network construction, analysis, and comparison for microbial compositional data
GNU General Public License v3.0
152 stars 27 forks source link

Is there a way to make 4 networks with the same layout? #42

Closed fpeti11 closed 2 years ago

fpeti11 commented 2 years ago

Hello Stefanie, I am quite new in network analysis. I would like to find out if the result that I got is a scale-free network or not? And I would like to measure modularity, is it possible to find out? Could you please help me how to find out these informations? I have a data set that can be divided into 4 categories. I would like to make 4 networks with the very same layout, to be more clear where are the differences. In the tutorial I found only 2 comparable categories, it didn’t work with 4 for me. Do you have a suggestion how to do this? Thank you for your help Peter

stefpeschel commented 2 years ago

Hey Peter,

NetCoMi is actually meant to compare two networks but you can store and reuse the layout so that several networks can be compared visually. Here's the code:

# Construct single network for the first group
net1 <- netConstruct(...)

# Construct single network for the second group
net2 <- netConstruct(...)

# Network analysis for  both groups
netprops1 <- netAnalyze(net1, ...)
netprops2 <- netAnalyze(net2, ...)

# Plot first network
p <- plot(netprops1, ...)

# Plot second network using the first layout
plot(netprops2, layout = p$layout$layout1, ...)

Instead of a single network, you could also construct, analyze, and plot two networks (using the plot arguments sameLayout = TRUE and layoutGroup = "union") and use the joint layout for a third group.

Regarding the scale-free property: You can compute and plot the degree distribution using functions of the igraph package:

net1 <- netConstruct(...)
g <- graph_from_adjacency_matrix(net1$adjaMat1, mode = "undirected", weighted = TRUE, diag = FALSE)
plot(degree_distribution(g), type = "l")

Alternatively, you could also directly take a look at the degree values computed by netAnalyze(), which can be accessed via netprops1$centralities$degree1.

For scale-free networks, the degree distribution should follow a power law.

The network's modularity is computed by netAnalyze() and can be accessed via netprops1$globalProps$modularity1 and is also shown in the summary.

Let me know if you have further questions.

Best, Stefanie