googleVis

Provides an interface between R and the Google Visualization API.

Creates interactive charts based on R data frames.

Requires an Internet connection and Adobe Flash.

install.packages("googleVis")
library(googleVis)

For usage restrictions, consult the Google APIs Terms and Conditions.

Bar Chart

plot.data <- reshape(sleep, direction = "wide",
                     timevar = "group", idvar = "ID")
names(plot.data)[2:3] <- c("Drug1", "Drug2")
plot.title <- "Student's Sleep Data: The Effects of Two Soporific Drugs"
p <- gvisBarChart(plot.data,
                  options = list(title = plot.title,
                                 hAxis = "{title:'Change in Hours of Sleep'}",
                                 vAxis = "{title:'Patient ID'}",
                                 width = 960, height = 600))
plot(p)

Bar Chart

Scatter Plot

plot.data <- women
plot.title <- "Average Heights and Weights for American Women, Ages 30 to 39"
p <- gvisScatterChart(data = plot.data,
                      options = list(legend = "none", title = plot.title,
                                     lineWidth = 2, pointSize = 0,
                                     hAxis = "{title:'Height (in.)'}",
                                     vAxis ="{title:'Weight (lbs.)'}",
                                     width = 960, height = 600))
plot(p)

Scatter Plot

Line Chart

plot.data <- cbind(data.frame(year = rownames(WorldPhones)), WorldPhones)[2:7, ]
plot.title <- "Number of Telephones in World Regions"
p <- gvisLineChart(plot.data,
                   options = list(title = plot.title,
                                  hAxis = "{title:'Year'}",
                                  vAxis = "{title:'Thousands of Phones'}",
                                  width = 960, height = 600))
plot(p)

Line Chart

Choropleth Map

options(stringsAsFactors = FALSE)
library(XML)
plot.data <- readHTMLTable("http://hdrstats.undp.org/en/indicators/100806.html")
plot.data <- plot.data$MainTable[5:198, c(2, 9)]
names(plot.data) <- c("Country", "Forest")
plot.title <- "Forest Area (Percent of Total Land Area)"
p <- gvisGeoChart(data = plot.data,
                  locationvar = "Country",
                  colorvar = "Forest",
                  options = list(title = plot.title,
                                 width = 960, height = 600))
plot(p)

Choropleth Map

Geo Marker Map

options(stringsAsFactors = FALSE)
library(XML)
plot.title <- "Track of Hurricane Irene"
plot.data <- readHTMLTable("http://www.wunderground.com/hurricane/at20119.asp")
plot.data <- plot.data$stormList
plot.data <- within(plot.data, coord <- paste(Lat, Lon, sep = ":"))
p <- gvisGeoChart(data = plot.data,
                  locationvar = "coord",
                  colorvar = "Pressure",
                  sizevar = "Wind (mph)",
                  options = list(region = "US", title = plot.title,
                                 width = 960, height = 600))
plot(p)

Geo Marker Map

Motion Chart

url <- "http://qacprojects.wesleyan.edu/data/gvisMotionChart_Data.csv"
plot.data <- read.csv(url)
plot.title <- "GDP versus Life Expectancy"
p <- gvisMotionChart(plot.data, idvar = "country", timevar = "year",
                     options = list(title = plot.title,
                                    width = 960, height = 600))
plot(p)

Motion Chart

/

#