Fruchterman-Reingold placement code by Carter T. Butts. Identical seed coordinates do not return identical network graphs.
Last active
January 1, 2016 23:59
-
-
Save briatte/8220340 to your computer and use it in GitHub Desktop.
controlling the seed.coord of Fruchterman-Reingold placement does not return identical graphs
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(network) | |
library(ggplot2) | |
library(grid) | |
# basic random network | |
x <- 10 | |
ndyads <- x * (x - 1) | |
density <- x / ndyads | |
nw.mat <- matrix(0, nrow = x, ncol = x) | |
dimnames(nw.mat) <- list(1:x, 1:x) | |
nw.mat[row(nw.mat) != col(nw.mat)] <- runif(ndyads) < density | |
nw.mat | |
rnd <- network(nw.mat) | |
rnd | |
# create layout coordinates | |
(n <- network.size(rnd)) | |
tempa <- sample((0:(n - 1))/n) | |
x <- n/(2 * pi) * sin(2 * pi * tempa) | |
y <- n/(2 * pi) * cos(2 * pi * tempa) | |
(tempa <- cbind(x,y)) | |
# requires ggnet with layout.par argument | |
for(i in 1:4) | |
assign(paste0("plot", i), ggnet(rnd, layout.par = list(seed.coord = tempa), label = TRUE, alpha = 1, size = 8, color = "white", segment.color = "grey10")) | |
vplayout <- function(x, y) viewport(layout.pos.row = x, layout.pos.col = y) | |
grid.newpage() | |
pushViewport(viewport(layout = grid.layout(2, 2))) | |
print(plot1, vp = vplayout(1, 1)) | |
print(plot2, vp = vplayout(1, 2)) | |
print(plot3, vp = vplayout(2, 1)) | |
print(plot4, vp = vplayout(2, 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment