R-Chart, and kindly contributed to Want to share your content on R-bloggers? [This article was first published on, and kindly contributed to R-bloggers ]. (You can report issue about the content on this page here Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Graph a github user’s followers (and follower’s followers).

Each programming language tends to develop its own idiomatic set of data structures. In R, data frames are often the structure of choice. JSON (a subset of Javascript) has emerged as an open standard for data interchange that has largely displaced XML for many web based APIs. This post gives an example of how to read JSON from GitHub, manipulate the data within R and produce a graph of the results (like the one above).

A few standard R libraries are required:

RCurl to retrieve JSON data (or anything else) from a URL

rjson to to parse the JSON data

In this particular API call (an example of json returned – no API key is required for the Github API), the JSON data will represent a GitHub user’s (first thirty) followers. This implies the use of a graph to represent the data so the igraph library will be used as well.

With the RCurl and rjson libraries available, the json results can be retrieved and converted to an R list as follows:

o

You can check the class for yourself using class(o) and view the length of the list using length(o)



To convert the results to the data frame where rows represent followers and columns represent attributes, unlist the results, transpose the results and cast as a data frame:

df

That is the basic process – the rest of the code is the details related to getting the data into the iGraph object which can then be rendered using plot, tkplot (show above) or rglplot.