Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collapsing graph by clusters in igraph

Tags:

r

igraph

I want to collapse a graph into its respective communities/clusters. Let me illustrate this with the following toy example:

set.seed(123)

#toy graph
g <- barabasi.game(10) %>%
  as.undirected()

#identify communities 
c_g <- fastgreedy.community(g) 

There are three communities, as seen in the following graph.

enter image description here

I want to reduce the collapse the vertices so that vertices in the resulting graph correspond to the membership of the previous vertices. See the graph.

enter image description here

I'm new to the igraph package and I'm not familiar with the best way of dealing with igraph objects.

like image 361
Jacob H Avatar asked Jan 25 '16 19:01

Jacob H


People also ask

What are the classes of graph clustering?

Classes related to graph clustering. Clustering Class representing a clustering of an arbitrary ordered set. Cohesive​Blocks The cohesive block structure of a graph. Cover Class representing a cover of an arbitrary ordered set. Dendrogram The hierarchical clustering (dendrogram) of some dataset.

How to make a graph object from a correlation matrix?

A correlation matrix can be visualized as a network diagram. Each entity of the dataset will be a node. And 2 nodes will be connected if their correlation or distance reach a threshold ( 0.995 here). To make a graph object from the correlation matrix, use the graph_from_adjacency_matrix () function of the igraph package.

What is self tuned graph clustering?

This post explains the functioning of the spectral graph clustering algorithm, then it looks at a variant named self tuned graph clustering. This adaptation has the advantage of providing an estimation for the optimal number of clusters and also for the similarity measure between data points.

How do you find the number of clusters in a graph?

A second way to estimate the number of clusters is to analyze the eigenvalues ( the largest eigenvalue of L will be a repeated eigenvalue of magnitude 1 with multiplicity equal to the number of groups C. This implies one could estimate C by counting the number of eigenvalues equaling 1).


1 Answers

You could try contract:

library(igraph)
set.seed(123)
g <- barabasi.game(10) %>% as.undirected()
c_g <- fastgreedy.community(g) 
V(g)$name <- letters[1:vcount(g)]

g2 <- contract(g, membership(c_g), vertex.attr.comb=toString)

par(mfrow=c(1,2))
plot(g, vertex.color=membership(c_g))
plot(simplify(g2), vertex.color=1:vcount(g2))

enter image description here

like image 164
lukeA Avatar answered Oct 14 '22 14:10

lukeA