Create Motion Charts in R with the GoogleVis package

[This article was first published on Revolutions, 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.

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 their blog: Revolutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)