是否可以从网络图中获取坐标?

时间:2017-10-12 16:35:06

标签: r igraph sna gplots statnet

我想重现具有相同(或接近)布局的网络图。我知道igraph有tkplot.getcoords()函数。我想根据gplot的结果复制/获取/设置一组顶点坐标,这是SNA包的绘图功能。

我找过这样做的地方但没找到任何东西。任何帮助将不胜感激。

编辑:添加了可重现的示例。我想让所有9个图都具有相同的布局,而不使用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

1 个答案:

答案 0 :(得分:2)

将绘图分配给对象,然后将其传递给coords =内的参数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) 
}

如果你检查&#39; l&#39;你可以看到它是一个x,y坐标的矩阵。

> 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

相关问题