Created
February 27, 2021 17:14
-
-
Save SachaEpskamp/468fa919a8167edb254d660a8baeff15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("bootnet") | |
library("qgraph") | |
# This sets the constraint. 1 for normal behavior, higher for more constrained layouts: | |
constrain <- 10 | |
# Three similar networks: | |
net1 <- genGGM(10, p = 0.1, propPositive = 1, nei = 2) | |
net2 <- genGGM(10, p = 0.1, propPositive = 1, nei = 2) | |
net3 <- genGGM(10, p = 0.1, propPositive = 1, nei = 2) | |
# In a list: | |
networks <- list(net1, net2, net3) | |
# Average them and compute a non-scaled layout: | |
avg_net <- Reduce("+", networks) / length(networks) | |
# Layout for initial: | |
layout_init <- qgraph(avg_net, layout = "spring", DoNotPlot=TRUE)$layout.orig | |
# Now plot per network: | |
pdf("networks.pdf") | |
for (i in seq_along(networks)){ | |
# Number of nodes: | |
n <- ncol(networks[[i]]) | |
# New layout parameters: | |
layout.par <- list( | |
max.delta = n / constrain, | |
area = n^2.3, | |
repulse.rad = n^2.8, | |
layout_init = layout_init) | |
# Plot: | |
qgraph(networks[[i]], layout = "spring", | |
layout.par = layout.par) | |
} | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment