3

I wonder if it's possible to "save" the layout of an igraph network so that others are able to reproduce the same graph? For now, the Fruchterman Reingold algorithm always create a newly looking network...

par(mfrow=c(1,2))
g <- erdos.renyi.game(100, 1/100)
V(g)$size<-seq(0.05,5,0.05)

layout <- layout.fruchterman.reingold(g)
plot(g, 
     layout=layout, 
     vertex.label=NA)
g

So essentially, can I somehow save & export the "layout" information?

Rnaldinho
  • 421
  • 2
  • 6
  • 15

2 Answers2

3

Set the random number generator seed with set.seed() before layout, e.g.:

library(igraph)

g <- erdos.renyi.game(100, 1/100)
V(g)$size<-seq(0.05,5,0.05)

par(mfrow = c(2,2))

layout <- layout.fruchterman.reingold(g)
plot(g, layout=layout, vertex.label = NA, main = "No seed 1")
layout <- layout.fruchterman.reingold(g)
plot(g, layout=layout, vertex.label = NA, main = "No seed 2")

set.seed(1)
layout <- layout.fruchterman.reingold(g)
plot(g, layout=layout, vertex.label = NA, main = "With seed 1")
set.seed(1)
layout <- layout.fruchterman.reingold(g)
plot(g, layout=layout, vertex.label = NA, main = "With seed 2")

enter image description here

zx8754
  • 52,746
  • 12
  • 114
  • 209
3

An igraph layout is simply a matrix with N rows and 2 columns, so you can save the matrix and then load it back later. Another option is to assign the first column of the matrix to a vertex attribute named x and the second to a vettex attribute named y - igraph will then use this layout when you plot the graph without specifying the layout parameter.

Tamás
  • 47,239
  • 12
  • 105
  • 124