R in 5 lines or less: Dataviz with the Google Charts API

Google chart options

A few of the many data visualization options available through the Google Charts API, which you can tap into using an R package.

Credit: Google

Want to tap into the Google Charts API with just a few lines of code? There's an R package for that.

For this example, I've graphed daily high and low temperatures in Fargo, ND (known for large temperature swings).

If you'd like to try this yourself, the code is below. Note that if you don't already have the googleVis library installed on your system, you'll need to install it first with the command install.packages("googleVis"). You'll also need R installed on your system; in addition, I'd recommend using RStudio for your R environment.

You can find the data file on GitHub -- either download it through git, manually or with the R command:

download.file(destfile = "fargoTemps2014.csv", method = "curl", url="")

Once you've got the data, this code will create an editable graph, which should open in your default browser:

 fargo <- read.csv("fargoTemps2014.csv", colClasses = c("Date", "integer", "integer"))
mychart <- gvisLineChart(fargo, options=list(gvis.editor="Edit this chart", width=1000, height=600))

There are many more types of visualizations you can make with googleVis and the Google Charts API -- everything from bar graphs and tables to maps, bubble charts and calendar heat maps. To see more examples, run the googleVis vignette with this R code:

vignette("googleVis_examples", package="googleVis") .

Why is Apple letting Macs rot on the tree?
View Comments
Join the discussion
Be the first to comment on this article. Our Commenting Policies