2012-10-02 54 views
8

我一直在尋找這個問題的答案,但找不到任何提及,所以我決定在這裏發佈。我想看看是否IGRAPH或任何封裝提供了一種簡單的方法來創建一個「社會圖」,其中每個節點代表一個社區網和聯繫代表的團體之間的聯繫。我能得到社會各界檢測算法的工作中的igraph很好,但我不能找到一種方法,崩潰的結果,只顯示每個社區之間的聯繫。任何援助將不勝感激。在igraph中生成社區圖我

+1

是的,這可以用igraph完成,但你真的沒有提供任何可重複的。這是我在igraph [(LINK1)](http://trinkerrstuff.wordpress.com/2012/06/29/igraph-and-structured-text-exploration/)和[(LINK 2)](http ://trinkerrstuff.wordpress.com/2012/06/30/igraph-and-sna-an-amateurs-dabbling/)是自我推銷,但它適合:) igraph的網站也很好,有很多例子。再次,我們可以通過一個示例數據集進一步幫助。 –

+0

+1給示例數據。 – TARehman

回答

19

您可以簡單地使用contract.vertices()函數。這將頂點組合同一個頂點,基本上與你想要的方式相同。例如。

library(igraph) 

## create example graph 
g1 <- graph.full(5) 
V(g1)$name <- 1:5  
g2 <- graph.full(5) 
V(g2)$name <- 6:10 
g3 <- graph.ring(5) 
V(g3)$name <- 11:15 
g <- g1 %du% g2 %du% g3 + edge('1', '6') + edge('1', '11') 

## Community structure 
fc <- fastgreedy.community(g) 

## Create community graph, edge weights are the number of edges 
cg <- contract.vertices(g, membership(fc)) 
E(cg)$weight <- 1 
cg2 <- simplify(cg, remove.loops=FALSE) 

## Plot the community graph 
plot(cg2, edge.label=E(cg2)$weight, margin=.5, layout=layout.circle) 
+2

看起來不再像這樣的代碼了... –

+2

的確,我修正了它。 –

相關問題