2

Basically I have tried a few different ways of clustering. I can usually get to a point in iGraph where each node is labeled with a cluster. I can then identify all the nodes within a single cluster. However, this loses their edges.

I'd have to re-iterate back over the original dataset for all the nodes in cluster 1 to get only those where both nodes+the edge are within the cluster. I'd have to do this for every cluster.

This seems like a painfully long process and there is probably a shortcut my google-fu is missing.

So, is there an easy way to, after clustering or performing community detection processes, to maintain an individual cluster/community as its own smaller graph -- that is, retaining all nodes AND edges between them?

  • Check out `?decompose.graph`. For a more detailed answer, it would help to include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output. – MrFlick Apr 19 '15 at 17:47

2 Answers2

2

You can use delete.vertices() to create a subgraph. Example:

library(igraph)

set.seed(123)

# create random graph
g <- barabasi.game(100, directed = F)
plot(g, layout=layout.fruchterman.reingold)

# do community detection
wc <- multilevel.community(g)
V(g)$community <- membership(wc)

# make community 1 subgraph
g_sub <- delete.vertices(g, V(g)[community != 1])
plot(g_sub, layout=layout.fruchterman.reingold)
sahoang
  • 375
  • 3
  • 9
0

An alternative:

#Create random network
d <- sample_gnm(n=50,m=40)

#Identify the communities
dc <- cluster_walktrap(d)

#Induce a subgraph out of the first community
dc_1 <- induced.subgraph(d,dc[[1]])

#plot that specific community
plot(dc_1)
NBK
  • 887
  • 9
  • 20