How to build only large communities / clusters in R

I have igraph in g. Since the timeline is huge, I only want to create communities with more than 10members, but I want them to display them in a single plot. My idea is to remove unnecessary items:

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

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

+4
source share
1 answer

Your idea is great, but the problem is that

igraph::clusters(g)$csize < 10

returns only a logical cluster vector containing less than 10 members. Meanwhile, you need to know which vertices belong to these clusters.

Therefore, we can act 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)

enter image description here

+1
source

Source: https://habr.com/ru/post/1694680/


All Articles