簡體   English   中英

在igraph中生成社區圖

[英]generating a community graph in igraph

我一直在尋找這個問題的答案,但找不到任何提及,所以我決定在這里發帖。 我試圖看看igraph或任何包提供了一種簡單的方法來創建“社區圖”,其中每個節點代表網絡中的社區,並且關系代表社區之間的聯系。 我可以讓社區檢測算法在igraph中正常工作,但我找不到一種方法來折疊結果,只顯示每個社區之間的連接。 任何援助將不勝感激。

您只需使用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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM