How to plot only large communities/clusters in R

ぃ、小莉子 提交于 2021-01-02 07:16:38

问题


I have an igraph in g. Since the graph is huge I only want to plot communities with more than 10 members, but I want to plot them all in one plot. My idea to remove unwanted elements is:

g <- delete_vertices(g, V(g)[igraph::clusters(g)$csize < 10])

but for some reason this plots a lot of single nodes, which is the opposite of what I try to achieve. Can you tell me where I am wrong?


回答1:


Your idea is great, but the problem is that

igraph::clusters(g)$csize < 10

only returns a logical vector of clusters containing fewer than 10 members. Meanwhile, you need to know which vertices belong to those clusters.

Hence, we may proceed as follows.

set.seed(1)
g1 <- erdos.renyi.game(100, 1 / 70)
cls <- clusters(g1)
cls$csize
#  [1]  1  1 43  2 11  1  1  1  2  1  2  5  1  1  4  4  1  1  1  1  2  1  2  1
# [25]  4  1  1  1  1  1 # Two clusters of interest
g2 <- delete_vertices(g1, V(g1)[cls$membership %in% which(cls$csize <= 10)])
plot(g2)



来源:https://stackoverflow.com/questions/49193512/how-to-plot-only-large-communities-clusters-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!