Contracting and simplifying a network graph

August 5, 2015

(This article was first published on Revolutions, and kindly contributed to R-bloggers)

by Andrie de Vries

In a previous post, I used page rank and community structure to create a plot of CRAN.  This plot used vibrant colours to allow us to see some of the underlying structure of CRAN.

However, much of this structure was still obfuscated by the amount of detail. Concretely, a large number of dots (packages) made it difficult to easily see the community structure.

Some more investigation followed, and I discovered a few beautiful functions in the igraph package that allows you to contract and simplify a graph:

  • The function contract.vertices() merges several vertices into one. By computing the community structure, one can control how this merging happens. At conclusion of the contraction, two vertices can have multiple edges.
  • The equivalent step for edges is simplify(). A simplified graph contains only a single edge between two nodes. The simplification step can compute summary statistics for the combined edges, for example the sum of edge weights.


Here is the code:


To leave a comment for the author, please follow the link and comment on their blog: Revolutions. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)