Create Motion Charts in R with the GoogleVis package

January 11, 2011
By

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

Hans Rosling popularized Motion Charts -- 2-d scatterplots that animate over time -- with the GapMinder project. Motion Charts were taken to their augmented-reality extreme in this clip from the BBC programme, The Joy of Stats, but now you can create similar (if less audacious) motion charts for yourself with just R and a Flash-enabled browser. 

First, you'll need to install the googleVis package from CRAN, and then use the gvisMotionChart to create an object in R. Then, you'll need to export part of it to a text file, and embed the HTML into a web page. The googleVis documentation explains the details but a good place to start is tutorial. I followed it and with these four lines of R code:

install.packages("googleVis")
library(googleVis)
M <- gvisMotionChart(Fruits, "Fruit", "Year")
cat(M$html$chart, file="tmp.html")

I was able to create a page just like this. If course, you can take this further and create animated visualizations of real data just as the Spatial Analysis blog has done, to create motion plots very similar to those from the GapMinder application. Check them out at the link below.

Spatial Analysis: R interface to Google Chart Tools

 

 

To leave a comment for the author, please follow the link and comment on his blog: Revolutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: 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...

Tags: , ,

Comments are closed.