The googleVis package provides an interface between R and the Google’s Chart Tools. The package provides interfaces to but not limited to the following:
It allows users to create web pages with interactive charts based on R data frames. While it uses Google’s Chart Tools, the data remains local and is not uploaded to Google. The authors, Markus Gesmann, Diego de Castillo, Joe Cheng, and Ashley Baldry, created this package after the 2006 Ted Talk by Hans Rosling on social and economic developments in the world over the past 50 years where Rosling displayed and soon popularized the the idea and use of interactive charts. Google then purchased Rosling’s initial software and integrated it into their own Google Charts API to make googleVis.
These charts could be used to illustrate data in a manner that is better presentable and more aesthetically pleasing. For example, rather than listing our data points about the electoral college in a list format, one could use the Geo Chart feature of googleVis to represent the data in a cleaner, more digestible fashion. Additionally, candidates could use the Bubble Chart feature of googleVis to see pockets of Democrats and Republicans in swing states to identify which regions specifically they should work on. If that’s not enough and the candidate wants to further pursue his odds of getting the votes, he could utilize the Candlestick Chart feature of googleVis to see the outliers of swing voters in each of the regions identified in the Bubble Chart to know exactly which voters he has the best probability of getting the vote. The possibilities are endless.
inventory_chart <- gvisBubbleChart(Fruits, idvar="Fruit",
xvar="Sales", yvar="Expenses",
options = list(width = "automatic",
height = "automatic"))
plot(inventory_chart)
inventory_chart2 <- gvisBubbleChart(Fruits, idvar="Fruit",
xvar="Sales", yvar="Expenses", colorvar = "Year",
options = list(width = 750,
height = "Automatic"))
plot(inventory_chart2)
inventory_chart3 <- gvisBubbleChart(Fruits, idvar="Fruit",
xvar="Sales", yvar="Expenses", colorvar = "Year",
sizevar = "Profit", options = list(width = 750,
height = "Automatic"))
plot(inventory_chart3)
inventory_chart4 <- gvisBubbleChart(Fruits, idvar="Fruit",
xvar="Sales", yvar="Expenses", colorvar = "Year",
sizevar = "Profit", options = list(title = "Johnny's Inventory",
vAxis = "{title:'Expenses', titleTextStyle: {color: 'gray'}}",
hAxis="{title:'Sales', titleTextStyle: {color: 'gray'}}",
colors="['#cbb69d', '#603913', '#c69c6e']", width = 750,
height = "Automatic"))
plot(inventory_chart4)
# First group by the year to get the sum of values for all fruits across the 3 years
sales_grouped <- Fruits %>% group_by(Year) %>% summarise(values = sum(Sales))
sales_grouped$Year <- as.character(sales_grouped$Year)
# Plot the data with the x-axis being the 3 years
sales <- gvisLineChart(sales_grouped, xvar = "Year", options = list(interpolateNulls = FALSE, width = 750,
height = "Automatic"))
plot(sales)
#Break up fruits into different dataframes
Apples = filter(Fruits, Fruit == "Apples")
Oranges = filter(Fruits, Fruit == "Oranges")
Bananas = filter(Fruits, Fruit == "Bananas")
#Create new dataframe with year as character and each fruit's sales as a seperate variable
salesBy = data.frame(Year = as.character(unique(Fruits$Year)), Apples = Apples$Sales, Oranges = Oranges$Sales, Bananas = Bananas$Sales)
#Create line chart
byFruit = gvisLineChart(salesBy, xvar = "Year", options = list(colors="['#cbb69d', '#603913', '#c69c6e']", width = 750,
height = "Automatic"))
plot(byFruit)
papaya <- Fruits %>% group_by(Fruit) %>% summarize(popularity = mean(Sales))
piedataframe <- data.frame(fruit = papaya$Fruit, popularity = papaya$popularity)
Pie <- gvisPieChart(piedataframe, options = list(title = "Fruits by Popularity", width = 750, height = "Automatic"))
plot(Pie)
papaya <- Fruits %>% group_by(Fruit) %>% summarize(popularity = mean(Sales))
piedataframe <- data.frame(fruit = papaya$Fruit, popularity = papaya$popularity)
Pie <- gvisPieChart(piedataframe, options = list(title = "Fruits by Popularity", is3D = TRUE, width = 750, height = "Automatic"))
plot(Pie)
papaya <- Fruits %>% group_by(Fruit) %>% summarize(popularity = mean(Sales))
Gauge <- gvisGauge(papaya,
options=list(min=0, max=200, greenFrom=100,
greenTo=200, yellowFrom=50, yellowTo=100,
redFrom=0, redTo=50, width=600, height=400))
plot(Gauge)
require(datasets)
states <- data.frame(state.name, state.x77)
colnames(states)[4] <- "Profits"
GeoStates <- gvisGeoChart(states, "state.name", "Profits", options=list(region="US", displayMode="regions", resolution="provinces", width=600, height=400))
plot(GeoStates)
#The dataset isn't directly for the profits per sale but is used in this context for demonstration purposes.
require(datasets)
states <- data.frame(state.name, state.x77)
colnames(states)[4] <- "Profits"
GeoStates <- gvisGeoChart(states, "state.name", "Profits", options=list(region="US-VA", displayMode="regions", resolution="metros", width=600, height=400))
plot(GeoStates)
# However, with this gvisGeoChart will automatically take out color indications and labels
GeoMarker <- gvisGeoChart(Andrew, "LatLong",
sizevar='Speed_kt',
colorvar="Pressure_mb",
options=list(region="US", width = 750,
height = "Automatic"))
plot(GeoMarker)
## Set options back to original options
options(op)