by Andrie de Vries

In my previous post on The network structure of CRAN I demonstrated how to use page rank and communities to visualize the structure of a graph.

At UseR!2015 I discussed my work with Gabor Csardi, the maintainer of the igraph package. Gabor gave me lots of helpful advice.

One nugget was how to use the networkD3 package (available on CRAN) to visualize a graph dynamically using javascript.

Once you have an igraph object, it is quite trivial to use networkD3 to plot the graph:

- Use igraph::get.data.frame() to create a data frame from the igraph object
- Use networkD3::simpleNetwork() to plot the graph

If you use RStudio as your IDE, then your plot is displayed directly in the RStudio viewer. This is because networkD3 uses htmlWidgets framework to display javascript objects in R, and RStudio supports this really well. If you use a different IDE, then your plot is displayed in an external browser window

Here is my code. I import a pre-saved graph directly from github, where I stored my scripts and intermediated object for the The network structure of CRAN presentation. For simplicity, I first create a subset of influential packages, only those with more than 50 edges:

And here is the result. Note that the plot is dynamic - you can drag any of the nodes to re-arrange the layout:

Nice! You may also be interested in the recent ndtv-d3 add-on we've just released in the statnet ndtv R package for visualizing network objects. Allows interactive HTML5 rendering of static and dynamic graphs with zooming, tooltips, and neighbour hilighting. Tutorial and examples at http://statnet.csde.washington.edu/workshops/SUNBELT/current/ndtv/ndtv-d3_vignette.html

Posted by: Skye Bender-deMoll | August 07, 2015 at 16:26