rigraphsnagplotsstatnet

Is it possible to get coordinates from network plots?


I'd like to reproduce a network graph with the same (or close) layout. I know that igraph has the tkplot.getcoords() function. I'd like to copy/get/set.seed a set of vertex coordinates based on the results of gplot, which is the SNA package's plotting function.

I've looked for places to do this but haven't found anything. Any help would be much appreciated.

EDIT: Added a reproducible example. I'd like to have all 9 plots have the same layout without using igraph::tkplot.

library(statnet)

set.seed(101)
mydata <- data.frame(from = sample(1:15,10,replace = T),
          to = sample(1:5,10,replace = T))



par(mfrow=c(3,3), mar=c(1,1,1,1))
k <- 1:9
for (i in 1:9) {
  gplot(network(mydata),main = paste('Iteration',k[i])) 
}

enter image description here


Solution

  • Assign the plot to an object and then pass that to the argument coords = within gplot.

    library(statnet)
    
    set.seed(101)
    mydata <- data.frame(from = sample(1:15,10,replace = T),
                         to = sample(1:5,10,replace = T))
    
    
    l <- gplot(network(mydata))
    par(mfrow=c(3,3), mar=c(1,1,1,1))
    k <- 1:9
    for (i in 1:9) {
      gplot(network(mydata),main = paste('Iteration',k[i]), coord = l) 
    }
    

    If you inspect 'l' you can see that it is a matrix of x, y coordinates.

    > l
                   x          y
     [1,] -0.4123840 -13.450699
     [2,]  6.1177559  -8.707917
     [3,]  0.5330693 -10.061580
     [4,] -1.5359554 -11.325280
     [5,]  2.7944671 -10.988359
     [6,]  5.1480964 -10.557675
     [7,] -1.7695806  -5.636370
     [8,]  2.2053996  -4.643251
     [9,]  1.8990660 -13.347872
    [10,]  2.1035474  -8.824222
    [11,] -3.3637096 -10.181900
    

    enter image description here