2017-10-12 73 views
1

我想用相同(或關閉)佈局重現網絡圖。我知道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

+0

這將是更容易幫助你,如果你提供的[重複的例子(https://stackoverflow.com/questions/5963269/how-to-make-a-great-r - 可重複生成的示例),其中包含一些示例輸入數據和對所需輸出的清晰描述。 – MrFlick

+0

@MrFlick,謝謝。我已經添加了上面的示例。有關如何捕獲迭代1的座標並將其應用於所有其他迭代的想法? – elliot

回答

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

如果檢查'l',則可以看到它是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

+0

完美!非常感謝。 – elliot

相關問題