video

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="https://raw.githubusercontent.com/smach/Rin5lines/master/data/fargoTemps2014.csv")

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"))
library("googleVis")
mychart <- gvisLineChart(fargo, options=list(gvis.editor="Edit this chart", width=1000, height=600))
plot(mychart)

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.
Windows 10 annoyances and solutions
Shop Tech Products at Amazon
Notice to our Readers
We're now using social media to take your comments and feedback. Learn more about this here.