Github Follower Graph with R

May 17, 2012

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

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 <- fromJSON(getURL(‘’))

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 <-, unlist)))

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. 

To leave a comment for the author, please follow the link and comment on their blog: R-Chart. 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.


Mango solutions

RStudio homepage

Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training


CRC R books series

Contact us if you wish to help support R-bloggers, and place your banner here.

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)