Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot only large communities/clusters in R

Tags:

r

igraph

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?

like image 497
DiCaprio Avatar asked Nov 08 '22 09:11

DiCaprio


1 Answers

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)

enter image description here

like image 74
Julius Vainora Avatar answered Nov 14 '22 22:11

Julius Vainora