It may be a cliché, but much of R’s utility comes from its amazing community. And by community, I am specifically referring to the bright, hard-working people who are willing to share their knowledge and code with the rest of us. Because of their contributions, we can do some amazingly cool and useful things with very little code of our own. It is in this context that I launch this new series to highlight packages and functions which make it easy to do jaw-droppingly cool and useful things.
First up: the googleVis package by Markus Gesmann and Diego de Castillo which makes it easy — often with just one-line of R — to harness the Google Visualization API. Annotated timelines, gauges, maps, org charts, tree maps, and more are suddenly at your command.
I’m going to focus on the motion chart, popularized by Hans Rosling in his groundbreaking 2006 TED talk on global economic development. (If you haven’t seen it yet, you should. Right now. Seriously. Go.) Motion charts are an innovative way to display multidimensional time series in an interactive way. And the googleVis package even comes with some sample data to make it even easier to try them out.
The package is available from CRAN if you need to install it.
To get started, load the package and the included “Fruits”
data.frame contains some sample data about sales of various fruits at different locations for different years. There’s even a proper
Date column already constructed for us from the
numeric Year column:
To make the chart, we need to give the
gvisMotionChart() function our
data.frame and tell it a few things about it: the column which identifies the items to examine (
idvar=Fruit), the time dimension (
M = gvisMotionChart(data=Fruits, idvar="Fruit", timevar="Date", chartid="ILoveFruit")
You can view your chart with the overridden
plot() function. It will automatically spawn a browser window and serve up your chart through R’s internal web server:
Time suck alert: googleVis may make them easy to create, but motion charts can be a lot of fun to play with. You have been warned…
If you want to take a look at an example with some real data, you might be interested in the 20 Years of the U.S. Domestic Airline Market In 20 seconds post on my work blog.
Finally, here are the slides from my lightning talk on this topic at this month’s Greater Boston useR Group meeting:
July 15, 2011 at 1:09 AM
Thanks for the post. The new version (0.2.7) of googleVis has a section in the vignette explaining how to use the package output with WordPress. Basically you need a plugin, e.g. “custom fields shortcode”, for more details and an example see:
July 15, 2011 at 8:06 AM
Thanks for dropping by — and thanks especially for the googleVis!
I found some info on the custom fields plugin, but I got the impression it’s only available for self-hosted WordPress blogs. For once in my (IT) life, I’ve taken the easy route and am using WordPress.com’s hosted service. (That’ll teach me!) But I’m sure it will help the WordPress.org’ers out there!
July 15, 2011 at 3:36 PM
[…] questo post di Jeffrey Breen che ha come oggetto l’integrazione di R con Google Visualization API […]
July 19, 2011 at 11:14 AM
[…] on T…Abhijit Sanyal on slides from my R tutorial on T…R & GoogleVis #2… on One-liners which make me love …Jeffrey Breen on installing R 2.13.1 on Amazon …Jeffrey Breen on installing R 2.13.1 on […]
August 18, 2011 at 6:41 PM
The last line creates an empty html file.
August 18, 2011 at 10:22 PM
That’s odd — I just cut-and-pasted the code again it worked fine.
Are you able to see the visualization via
September 16, 2011 at 8:08 PM
[…] One-liners which make me love R: Make your data dance (Hans Rosling style) with googleVis […]
January 25, 2012 at 8:33 AM
That title is somehow misleading. That oneliner of R has a lot of lines of R, C, C++, or FORTRAN in the back.
It depends where the observer is positioned in the production chain between the final visualization and the raw data.
March 21, 2012 at 9:14 AM
Sorry I missed this in the comment queue–
That’s a great point, but it’s also my point (which I could have made clearer): much of the power of R comes from the generous contributions of others in the community. What I like about R is that I can do very complicated, sophisticated, and cool things without having to do much (or any!) of the heavy lifting myself.