简体   繁体   中英

Fixes positions for nodes in r igraph?

Suppose we want to visualise a network like the one below

library(igraph)
a<- cbind(c(1,2,3,4,5),
c(2,4,1,2,2))
b<- graph.edgelist(a, directed=FALSE)

Is there any way to keep the nodes in the same position apart from setting the coords by hand?? For example, can we edit the graph with tkplot and save the layout so that it remains the same no matter how many times we run the code? By using the function tkplot.getcoords , I manage to save the layout only once. Is repeatablility possible?

Thank you in advance.

A solution is to set a seed with set.seed :

library(igraph)
a<- cbind(c(1,2,3,4,5),
c(2,4,1,2,2))
b<- graph.edgelist(a, directed=FALSE)

set.seed(123)
plot(b)

And you'll get this each time you run the code:

在此处输入图片说明

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.

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