Skip to content

Instantly share code, notes, and snippets.

@briatte
Last active January 1, 2016 23:59
Show Gist options
  • Save briatte/8220340 to your computer and use it in GitHub Desktop.
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
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