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

Google chart options
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") .

To express your thoughts on Computerworld content, visit Computerworld's Facebook page, LinkedIn page and Twitter stream.
10 super-user tricks to boost Windows 10 productivity
Shop Tech Products at Amazon