简体   繁体   English

R igraph-保存布局?

[英]R igraph - save layout?

I wonder if it's possible to "save" the layout of an igraph network so that others are able to reproduce the same graph? 我想知道是否有可能“保存” igraph网络的布局,以便其他人能够复制相同的图? For now, the Fruchterman Reingold algorithm always create a newly looking network... 目前,Fruchterman Reingold算法始终会创建一个新的网络...

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. igraph布局只是具有N行和2列的矩阵,因此您可以保存矩阵,然后将其加载回去。 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. 另一个选择是将矩阵的第一列分配给名为x的顶点属性,将第二列分配给名为y的vettex属性-然后,在您绘制图形时,igraph将使用此布局,而无需指定layout参数。

Set the random number generator seed with set.seed() before layout, eg: 在布局之前使用set.seed()设置随机数生成器种子,例如:

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")

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM