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?
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.
Set the random number generator seed with set.seed()
before layout, eg:
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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.