A Code Through
*github.com/tylerisyoung
_________________________
Let’s Install it
install.packages("googleVis")
We can read over the documentation or execute the extensive demo by using
??googleviz
#or
demo(googleVis)
Now lets load the library and visualize a few examples from the included data.
library(googleVis)
op <- options(gvis.plot.tag="chart")
Population Chart with interactive pages
PopTable <- gvisTable(Population, formats = list(Population = "#,###", `% of World Population` = "#.#%"),
options = list(page = "enable"))
plot(PopTable)
The popular Sankey Chart with interactive labels and
cursor highlighting
datSK <- data.frame(From = c(rep("A", 3), rep("B", 3)), To = c(rep(c("X", "Y", "Z"),
2)), Weight = c(5, 7, 6, 2, 9, 4))
Sankey <- gvisSankey(datSK, from = "From", to = "To", weight = "Weight", options = list(sankey = "{link: {color: { fill: '#d799ae' } },
node: { color: { fill: '#a61d4c' },
label: { color: '#871b47' } }}"))
plot(Sankey)
A simple histogram with interactive tags, a data.frame
to be displayed as a histogram. Each column will be displayed as a
histogram.
set.seed(12345)
datHist = data.frame(A = rpois(100, 20), B = rpois(100, 5), C = rpois(100, 50))
Hist <- gvisHistogram(datHist, options = list(legend = "{ position: 'top', maxLines: 2 }",
colors = "['#5C3112', '#3A5723', '#871B47']", width = 400, height = 360))
plot(Hist)
Or even an annotation chart with interactive plot
locations
Anno <- gvisAnnotationChart(Stock, datevar = "Date", numvar = "Value", idvar = "Device",
titlevar = "Title", annotationvar = "Annotation", options = list(width = 600,
height = 350, fill = 10, displayExactValues = TRUE, colors = "['#0000ff','#00ff00']"))
plot(Anno)
require(datasets)
states <- data.frame(state.name, state.x77)
exp <- gvisGeoChart(states, "state.name", "Life.Exp", options = list(region = "US",
displayMode = "regions", resolution = "provinces", width = 600, height = 400))
# It is also possible to use 'icon=paste0 to use custom icons from
# icons.iconarchive.com
plot(exp)
Note: You will need an internet connection to load the graphical data as they require api access to run.
Other links: Google Charts API: https://developers.google.com/chart/ Google Maps API Terms of Service: https://cloud.google.com/maps-platform/terms/