Title: | R Interface to Google Charts |
---|---|
Description: | R interface to Google's chart tools, allowing users to create interactive charts based on data frames. Charts are displayed locally via the R HTTP help server. A modern browser with an Internet connection is required. The data remains local and is not uploaded to Google. |
Authors: | Markus Gesmann [aut, cre], Diego de Castillo [aut], Joe Cheng [ctb], Ashley Baldry [ctb], Durey IngenierĂa [ctb] |
Maintainer: | Markus Gesmann <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.7.3 |
Built: | 2024-11-21 04:20:23 UTC |
Source: | https://github.com/mages/googlevis |
R interface to Google Charts API, allowing users to create interactive charts based on data frames. Charts are displayed locally via the R HTTP help server. A modern browser with Internet connection is required and for some charts Flash. The data remains local and is not uploaded to Google.
Please visit the project web site for more information: https://github.com/mages/googleVis.
You find further notes on Markus' blog: https://magesblog.com/tags/googlevis/
See vignette("googleVis")
for an introduction to the
googleVis
package.
Markus Gesmann, Diego de Castillo
Google Charts API: https://developers.google.com/chart/
Google Terms of Use: https://developers.google.com/terms/
Google Maps API Terms of Service: https://cloud.google.com/maps-platform/terms/
## Not run: demo(googleVis) ## For other demos see demo(package='googleVis') ## End(Not run)
## Not run: demo(googleVis) ## For other demos see demo(package='googleVis') ## End(Not run)
Hurricane Andrew storm path from 16 August to 28 August 1992
data(Andrew)
data(Andrew)
A data frame with 47 observations on the following 8 variables.
Date/Time UTC
a POSIXct
Lat
a numeric vector
Long
a numeric vector
Pressure_mb
a numeric vector
Speed_kt
a numeric vector
Category
a factor with levels Hurricane
Tropical Depression
Tropical Storm
LatLong
a character vector
Tip
a character vector
National Hurricane Center: https://www.nhc.noaa.gov/1992andrew.html
data(Andrew) AndrewGeoMap <- gvisGeoMap(Andrew, locationvar='LatLong', numvar='Speed_kt', hovervar='Category', options=list(width=800,height=400, region='US', dataMode='Markers')) AndrewMap <- gvisMap(Andrew, 'LatLong' , 'Tip', options=list(showTip=TRUE, showLine=TRUE, enableScrollWheel=TRUE, mapType='hybrid', useMapTypeControl=TRUE, width=800,height=400)) AndrewTable <- gvisTable(Andrew,options=list(width=800)) ## Combine the outputs into one page: AndrewVis <- gvisMerge(AndrewGeoMap, AndrewMap) plot(AndrewVis)
data(Andrew) AndrewGeoMap <- gvisGeoMap(Andrew, locationvar='LatLong', numvar='Speed_kt', hovervar='Category', options=list(width=800,height=400, region='US', dataMode='Markers')) AndrewMap <- gvisMap(Andrew, 'LatLong' , 'Tip', options=list(showTip=TRUE, showLine=TRUE, enableScrollWheel=TRUE, mapType='hybrid', useMapTypeControl=TRUE, width=800,height=400)) AndrewTable <- gvisTable(Andrew,options=list(width=800)) ## Combine the outputs into one page: AndrewVis <- gvisMerge(AndrewGeoMap, AndrewMap) plot(AndrewVis)
The average air temperature (C) in Cairo from 2002 to 2004.
data(Cairo)
data(Cairo)
A data frame with 1091 observations on the following 2 variables.
Date
calendar date
Temp
average temperatur in Celsius
Wood, S.N. (2006) Generalized Additive Models: An Introduction with R
data(Cairo) plot(gvisCalendar(Cairo))
data(Cairo) plot(gvisCalendar(Cairo))
A set of responses for search terms for cats
data(Cats)
data(Cats)
A data frame with 18 observations on the following 3 variables.
Phrase
Search term for cats
Size
Number of times term has been searched
Sentiment
Numeric value from 0-10 of sentiment of term
data(Cats) plot(gvisWordTree(Cats, textvar = "Phrase"))
data(Cats) plot(gvisWordTree(Cats, textvar = "Phrase"))
Example data set to illustrate the use of the googleVis package.
data(CityPopularity)
data(CityPopularity)
A data frame with 6 observations on the following 2 variables.
City
a factor with levels Boston
Chicago
Houston
Los Angeles
Miami
New York
Popularity
a numeric vector
Google Geo Map API: https://developers.google.com/chart/interactive/docs/gallery/geomap.html
data(CityPopularity) str(CityPopularity)
data(CityPopularity) str(CityPopularity)
Create a Google Gadget based on a Google Visualisation Object
createGoogleGadget(gvis)
createGoogleGadget(gvis)
gvis |
an object of class 'gvis', e.g. output of a googleVis visualisation functions. |
createGoogleGadget returns a Google Gadget XML string.
Google Gadgets can be embedded in various Google products, for example as part of a Google Code wiki page, Blogger or Google Sites. In all cases the XML gadget file has to be hosted online, e.g. using Google Docs.
In Blogger the gadgets can be embedded via the design tab, and in a Google Sites via the menu "Insert" -> "More gadgets ..." -> "Add gadget ULR".
In a Google Code wiki the gadget can be embedded via
<wiki:gadget url="https://example.com/gadget.xml" height="200" border="0" />
Markus Gesmann
See also as print.gvis
, cat
M <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year") gdgt <- createGoogleGadget(M) cat(gdgt)
M <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year") gdgt <- createGoogleGadget(M) cat(gdgt)
Lenght of dinosaurs
data(dino)
data(dino)
A data frame with 28 observations on 2 variables, dinosaur and length.
https://developers.google.com/chart/interactive/docs/gallery/histogram
data(dino) str(dino)
data(dino) str(dino)
Example data set to illustrate the use of the googleVis package.
data(Exports)
data(Exports)
A data frame with 10 observations on the following 3 variables.
Country
a factor with levels Brazil
, Germany
...
Profit
a numeric vector
Online
a logical vector
data(Exports) str(Exports)
data(Exports) str(Exports)
Example data set to illustrate the use of the googleVis package.
data(Fruits)
data(Fruits)
A data frame with 9 observations on the following 7 variables.
Fruit
a factor with levels Apples
Bananas
Oranges
Year
a numeric vector
Location
a factor with levels East
West
Sales
a numeric vector
Expenses
a numeric vector
Profit
a numeric vector
Date
a Date
data(Fruits) M <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year") ## Not run: plot(M) ## End(Not run)
data(Fruits) M <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year") ## Not run: plot(M) ## End(Not run)
Methods to print and plot gvis
objects
## S3 method for class 'gvis' print(x, tag=NULL, file = "", ...) ## S3 method for class 'gvis' plot(x, tag=NULL,...)
## S3 method for class 'gvis' print(x, tag=NULL, file = "", ...) ## S3 method for class 'gvis' plot(x, tag=NULL,...)
x |
An object of class |
tag |
Default A complete list of available tags is given by the command
The default value of The default tag for
|
file |
file name. If "" (the
default), output will be printed to the standard output connection,
the console unless redirected by |
... |
arguments passed on to |
An object of class "gvis
" is a list containing at least the
following components (tags):
type
Google visualisation type, e.g. 'MotionChart'
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
print.gvis |
None (invisible |
plot.gvis |
Returns the file name invisibly. |
The plot
command does not open a graphics device in the
traditional way. Instead it creates HTML files in a temporary
directory and uses the R HTTP server to display the output
of a googleVis
function locally.
A browser with Flash and Internet connection is required.
The displayed page includes a link (click on the chart id) to a
further page, which shows the code of the chart for the user to copy
and paste into her own page.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Please see also the package vignette for the usage of the googleVis package with RApache, brew, knitr and R.rsp.
See also cat
, browseURL
,
createGoogleGadget
and gvisMerge
for combining charts.
## Show gvis options sapply(c("gvis.print.tag", "gvis.plot.tag", "gvis.tags"), getOption) M <- gvisMotionChart(Fruits, "Fruit", "Year") str(M) ## The output for a complete web page M ## Access only the plot, M$html$chart ## wrap it in cat and it becomes more readable, cat(unlist(M$html$chart)) ## or use the print function. print(M, tag="chart") ## Extract the data as a JavaScript function. print(M, tag="jsData") ## Display the visualisation. ## A web browser with Internet connection and Flash is required. plot(M) ## Combine with another chart, e.g. table #tbl <- gvisTable(Fruits, options=list(height=220)) #Mtbl <- gvisMerge(M, tbl) #plot(Mtbl) ## Example of using googleVis with knitr and markdown ## Not run: ## Simple knitr/markdown file with googleVis knitrRmd <-" # Markdown example with knitr and googleVis =========================================== This is a little Markdown example file. Set the googleVis options first. In this case change the behaviour of plot.gvis ```{r setOptions, message=FALSE} library(googleVis) op <- options(gvis.plot.tag='chart') ``` The following plot statements will automatically return the HTML required for the 'knitted' output. ## Combo chart ```{r ComboExample, results='asis', tidy=FALSE} ## Add the mean CityPopularity$Mean=mean(CityPopularity$Popularity) CC <- gvisComboChart(CityPopularity, xvar='City', yvar=c('Mean', 'Popularity'), options=list(seriesType='bars', width=450, height=300, title='City Popularity', series='{0: {type:\"line\"}}')) plot(CC) ``` Example of gvisComboChart with R code shown above. ## Place two charts next to each other ```{r gvisMergeExample, results='asis', echo=FALSE} Geo <- gvisGeoChart(Exports, locationvar='Country', colorvar='Profit', options=list(height=300, width=350)) Tbl <- gvisTable(Exports, options=list(height=300, width=200)) plot(gvisMerge(Geo, Tbl, horizontal=TRUE)) `````` Example of a gvisGeoChart with gvisTable and R code hidden. ## Motion Chart ```{r MotionChartExample, results='asis', tidy=FALSE} M <- gvisMotionChart(Fruits, 'Fruit', 'Year', options=list(width=400, height=350)) plot(M) ``` Please note that the Motion Chart is only displayed when hosted on a web server, or is placed in a directory which has been added to the trusted sources in the [security settings of Macromedia] (https://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html). See the googleVis package vignette for more details. ```{r resetOptions} ## Set options back to original options options(op) ``` " ## Write the content of knitrRmd into a Rmd-file, knit it and convert it ## into a html output. Finally show the file with the R-help http ## server, this will ensure that also the motion chart is visible. library(knitr) library(markdown) wd <- getwd() setwd(tempdir()) fn=tempfile() fn.Rmd <- paste(fn, ".Rmd", sep="") fn.md <- paste(fn, ".md", sep="") fn.html <- paste(fn, "-out.html", sep="") ## Write R Markdown into a file cat(knitrRmd, file=fn.Rmd) render_markdown() knit(fn.Rmd, fn.md) knit2html(fn.md) ## Open output in browser ## Use plot.gvis which will use the R-help http server ## The URL will start with http://127.0.0.1... ## The HTML file will be copied into a temporary directory plot.gvis(fn.html) ## Compare to browseURL, its URL will start with file://... the motion ## chart is unlikely to be displayed because of Flash security ## settings. See the googleVis vignette for more details. browseURL(fn.html) setwd(wd) ## End(Not run) ## Not run: ## Updating the data of an existing googleVis web page ## Suppose you have an existing web page in which you embedded a ## motion chart with the id "mtnc". ## Now you have a new set of data, but you would like to avoid ## touching the html file again. ## The idea is to write the data and JavaScript functions into separate ## files and to refer to these in the html page. ## In this example we call the chart id "mtnc" ## To display the example we use the R HTTP server again, and ## write the files into a temp directory myChartID <- "mtnc" ## baseURL should reflect your web address, e.g. http://myHomePage.com baseURL <- sprintf("http://127.0.0.1:%s/custom/googleVis", tools:::httpdPort) wwwdir <- tempdir() ## the www repository on your computer ## Create a motion chart M=gvisMotionChart(Fruits, "Fruit", "Year", chartid=myChartID) ## Here is our plot again plot(M) ## Write the data and functions into separate files: cat(M$html$chart['jsData'], file=file.path(wwwdir, "gvisData.js")) cat(M$html$chart[c('jsDrawChart', 'jsDisplayChart', 'jsChart')], file=file.path(wwwdir, "gvisFunctions.js")) ## Create a html page with reference to the above ## JavaScript files html <- sprintf(' <html> <head> <script type="text/javascript" src="https://www.google.com/jsapi"> </script> <script type="text/javascript" src="%s/gvisFunctions.js"></script> <script type="text/javascript" src="%s/gvisData.js"></script> <script type="text/javascript"> displayChart%s() </script> </head> <body> <div id="%s" style="width: 600px; height: 500px;"></div> </body> </html> ', baseURL, baseURL, myChartID, myChartID) ## Write html scaffold into a file cat(html, file=file.path(wwwdir, paste("Chart", myChartID, ".html", sep=""))) ## Display the result via URL <- paste(baseURL,"/Chart", myChartID, ".html", sep="") browseURL(URL) ## Update the data, say the data should have shown North and South ## instead of East and West as a location FruitsUpdate <- Fruits levels(FruitsUpdate$Location)=c("North", "South") Mupdate=gvisMotionChart(FruitsUpdate, "Fruit", "Year", chartid=myChartID) ## Only update the file gvisData.js: cat(Mupdate$html$chart['jsData'], file=file.path(wwwdir, "gvisData.js")) ## Redisplay the chart with the updated data browseURL(URL) ## End(Not run)
## Show gvis options sapply(c("gvis.print.tag", "gvis.plot.tag", "gvis.tags"), getOption) M <- gvisMotionChart(Fruits, "Fruit", "Year") str(M) ## The output for a complete web page M ## Access only the plot, M$html$chart ## wrap it in cat and it becomes more readable, cat(unlist(M$html$chart)) ## or use the print function. print(M, tag="chart") ## Extract the data as a JavaScript function. print(M, tag="jsData") ## Display the visualisation. ## A web browser with Internet connection and Flash is required. plot(M) ## Combine with another chart, e.g. table #tbl <- gvisTable(Fruits, options=list(height=220)) #Mtbl <- gvisMerge(M, tbl) #plot(Mtbl) ## Example of using googleVis with knitr and markdown ## Not run: ## Simple knitr/markdown file with googleVis knitrRmd <-" # Markdown example with knitr and googleVis =========================================== This is a little Markdown example file. Set the googleVis options first. In this case change the behaviour of plot.gvis ```{r setOptions, message=FALSE} library(googleVis) op <- options(gvis.plot.tag='chart') ``` The following plot statements will automatically return the HTML required for the 'knitted' output. ## Combo chart ```{r ComboExample, results='asis', tidy=FALSE} ## Add the mean CityPopularity$Mean=mean(CityPopularity$Popularity) CC <- gvisComboChart(CityPopularity, xvar='City', yvar=c('Mean', 'Popularity'), options=list(seriesType='bars', width=450, height=300, title='City Popularity', series='{0: {type:\"line\"}}')) plot(CC) ``` Example of gvisComboChart with R code shown above. ## Place two charts next to each other ```{r gvisMergeExample, results='asis', echo=FALSE} Geo <- gvisGeoChart(Exports, locationvar='Country', colorvar='Profit', options=list(height=300, width=350)) Tbl <- gvisTable(Exports, options=list(height=300, width=200)) plot(gvisMerge(Geo, Tbl, horizontal=TRUE)) `````` Example of a gvisGeoChart with gvisTable and R code hidden. ## Motion Chart ```{r MotionChartExample, results='asis', tidy=FALSE} M <- gvisMotionChart(Fruits, 'Fruit', 'Year', options=list(width=400, height=350)) plot(M) ``` Please note that the Motion Chart is only displayed when hosted on a web server, or is placed in a directory which has been added to the trusted sources in the [security settings of Macromedia] (https://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html). See the googleVis package vignette for more details. ```{r resetOptions} ## Set options back to original options options(op) ``` " ## Write the content of knitrRmd into a Rmd-file, knit it and convert it ## into a html output. Finally show the file with the R-help http ## server, this will ensure that also the motion chart is visible. library(knitr) library(markdown) wd <- getwd() setwd(tempdir()) fn=tempfile() fn.Rmd <- paste(fn, ".Rmd", sep="") fn.md <- paste(fn, ".md", sep="") fn.html <- paste(fn, "-out.html", sep="") ## Write R Markdown into a file cat(knitrRmd, file=fn.Rmd) render_markdown() knit(fn.Rmd, fn.md) knit2html(fn.md) ## Open output in browser ## Use plot.gvis which will use the R-help http server ## The URL will start with http://127.0.0.1... ## The HTML file will be copied into a temporary directory plot.gvis(fn.html) ## Compare to browseURL, its URL will start with file://... the motion ## chart is unlikely to be displayed because of Flash security ## settings. See the googleVis vignette for more details. browseURL(fn.html) setwd(wd) ## End(Not run) ## Not run: ## Updating the data of an existing googleVis web page ## Suppose you have an existing web page in which you embedded a ## motion chart with the id "mtnc". ## Now you have a new set of data, but you would like to avoid ## touching the html file again. ## The idea is to write the data and JavaScript functions into separate ## files and to refer to these in the html page. ## In this example we call the chart id "mtnc" ## To display the example we use the R HTTP server again, and ## write the files into a temp directory myChartID <- "mtnc" ## baseURL should reflect your web address, e.g. http://myHomePage.com baseURL <- sprintf("http://127.0.0.1:%s/custom/googleVis", tools:::httpdPort) wwwdir <- tempdir() ## the www repository on your computer ## Create a motion chart M=gvisMotionChart(Fruits, "Fruit", "Year", chartid=myChartID) ## Here is our plot again plot(M) ## Write the data and functions into separate files: cat(M$html$chart['jsData'], file=file.path(wwwdir, "gvisData.js")) cat(M$html$chart[c('jsDrawChart', 'jsDisplayChart', 'jsChart')], file=file.path(wwwdir, "gvisFunctions.js")) ## Create a html page with reference to the above ## JavaScript files html <- sprintf(' <html> <head> <script type="text/javascript" src="https://www.google.com/jsapi"> </script> <script type="text/javascript" src="%s/gvisFunctions.js"></script> <script type="text/javascript" src="%s/gvisData.js"></script> <script type="text/javascript"> displayChart%s() </script> </head> <body> <div id="%s" style="width: 600px; height: 500px;"></div> </body> </html> ', baseURL, baseURL, myChartID, myChartID) ## Write html scaffold into a file cat(html, file=file.path(wwwdir, paste("Chart", myChartID, ".html", sep=""))) ## Display the result via URL <- paste(baseURL,"/Chart", myChartID, ".html", sep="") browseURL(URL) ## Update the data, say the data should have shown North and South ## instead of East and West as a location FruitsUpdate <- Fruits levels(FruitsUpdate$Location)=c("North", "South") Mupdate=gvisMotionChart(FruitsUpdate, "Fruit", "Year", chartid=myChartID) ## Only update the file gvisData.js: cat(Mupdate$html$chart['jsData'], file=file.path(wwwdir, "gvisData.js")) ## Redisplay the chart with the updated data browseURL(URL) ## End(Not run)
The gvisAnnotatedTimeLine function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page.
gvisAnnotatedTimeLine( data, datevar = "", numvar = "", idvar = "", titlevar = "", annotationvar = "", date.format = "%Y/%m/%d", options = list(), chartid )
gvisAnnotatedTimeLine( data, datevar = "", numvar = "", idvar = "", titlevar = "", annotationvar = "", date.format = "%Y/%m/%d", options = list(), chartid )
data |
a |
datevar |
column name of |
numvar |
column name of |
idvar |
column name of |
titlevar |
column name of |
annotationvar |
column name of |
date.format |
if |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/annotatedtimeline#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
An annotated time line is an interactive time series line chart with optional annotations. The chart is rendered within the browser using Flash.
gvisAnnotatedTimeLine returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
AnnotatedTimeline (gvisAnnotatedTimeLine) is no longer supported by Google. The annotated timeline now automatically uses Annotation Charts instead.
Important: To use this visualization, you must specify the height and width of the container element explicitly on your page. So, for example: options=list(width="600px", height="350px")
Use gvisAnnotationChart
for a non-Flash version of this plot.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/annotatedtimeline
See also print.gvis
, plot.gvis
for printing and
plotting methods. Further see reshape
for reshaping data, e.g.
from a wide format into a long format.
## Please note that by default the googleVis plot command ## will open a browser window and requires Flash and Internet ## connection to display the visualisation. data(Stock) Stock A1 <- gvisAnnotatedTimeLine(Stock, datevar="Date", numvar="Value", idvar="Device", titlevar="Title", annotationvar="Annotation", options=list(displayAnnotations=TRUE, legendPosition='newRow', width="600px", height="350px") ) plot(A1) ## Two Y-axis A2 <- gvisAnnotatedTimeLine(Stock, datevar="Date", numvar="Value", idvar="Device", titlevar="Title", annotationvar="Annotation", options=list(displayAnnotations=TRUE, width="600px", height="350px", scaleColumns='[0,1]', scaleType='allmaximized') ) plot(A2) ## Colouring the area below the lines to create an area chart A3 <- gvisAnnotatedTimeLine(Stock, datevar="Date", numvar="Value", idvar="Device", titlevar="Title", annotationvar="Annotation", options=list( width="600px", height="350px", fill=10, displayExactValues=TRUE, colors="['#0000ff','#00ff00']") ) plot(A3) ## Data with POSIXct datetime variable A4 <- gvisAnnotatedTimeLine(Andrew, datevar="Date/Time UTC", numvar="Pressure_mb", options=list(scaleType='maximized', width="600px", height="350px") ) plot(A4)
## Please note that by default the googleVis plot command ## will open a browser window and requires Flash and Internet ## connection to display the visualisation. data(Stock) Stock A1 <- gvisAnnotatedTimeLine(Stock, datevar="Date", numvar="Value", idvar="Device", titlevar="Title", annotationvar="Annotation", options=list(displayAnnotations=TRUE, legendPosition='newRow', width="600px", height="350px") ) plot(A1) ## Two Y-axis A2 <- gvisAnnotatedTimeLine(Stock, datevar="Date", numvar="Value", idvar="Device", titlevar="Title", annotationvar="Annotation", options=list(displayAnnotations=TRUE, width="600px", height="350px", scaleColumns='[0,1]', scaleType='allmaximized') ) plot(A2) ## Colouring the area below the lines to create an area chart A3 <- gvisAnnotatedTimeLine(Stock, datevar="Date", numvar="Value", idvar="Device", titlevar="Title", annotationvar="Annotation", options=list( width="600px", height="350px", fill=10, displayExactValues=TRUE, colors="['#0000ff','#00ff00']") ) plot(A3) ## Data with POSIXct datetime variable A4 <- gvisAnnotatedTimeLine(Andrew, datevar="Date/Time UTC", numvar="Pressure_mb", options=list(scaleType='maximized', width="600px", height="350px") ) plot(A4)
gvisAnnotationChart charts are interactive time series line charts that support annotations. Unlike the gvisAnnotatedTimeLine, which uses Flash, annotation charts are SVG/VML and should be preferred whenever possible.
gvisAnnotationChart( data, datevar = "", numvar = "", idvar = "", titlevar = "", annotationvar = "", date.format = "%Y/%m/%d", options = list(), chartid )
gvisAnnotationChart( data, datevar = "", numvar = "", idvar = "", titlevar = "", annotationvar = "", date.format = "%Y/%m/%d", options = list(), chartid )
data |
a |
datevar |
column name of |
numvar |
column name of |
idvar |
column name of |
titlevar |
column name of |
annotationvar |
column name of |
date.format |
if |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/annotationchart#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
gvisAnnotationChart returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected], Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/annotationchart
See also print.gvis
, plot.gvis
for printing and
plotting methods. Further see reshape
for reshaping data, e.g.
from a wide format into a long format.
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. data(Stock) Stock A1 <- gvisAnnotationChart(Stock, datevar="Date", numvar="Value", idvar="Device", titlevar="Title", annotationvar="Annotation", options=list(displayAnnotations=TRUE, legendPosition='newRow', width=600, height=350) ) plot(A1) ## Two Y-axis A2 <- gvisAnnotationChart(Stock, datevar="Date", numvar="Value", idvar="Device", titlevar="Title", annotationvar="Annotation", options=list(displayAnnotations=TRUE, width=600, height=350, scaleColumns='[0,1]', scaleType='allmaximized') ) plot(A2) ## Colouring the area below the lines to create an area chart A3 <- 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(A3) ## Data with POSIXct datetime variable A4 <- gvisAnnotationChart(Andrew, datevar="Date/Time UTC", numvar="Pressure_mb", options=list(scaleType='maximized') ) plot(A4) # Change background to blue A5 <- gvisAnnotationChart(Stock, datevar="Date", numvar="Value", idvar="Device", titlevar="Title", annotationvar="Annotation", options=list( displayAnnotations=TRUE, chart = "{chartArea:{backgroundColor:'#003b70'}}", legendPosition='newRow', width=600, height=350)) plot(A5)
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. data(Stock) Stock A1 <- gvisAnnotationChart(Stock, datevar="Date", numvar="Value", idvar="Device", titlevar="Title", annotationvar="Annotation", options=list(displayAnnotations=TRUE, legendPosition='newRow', width=600, height=350) ) plot(A1) ## Two Y-axis A2 <- gvisAnnotationChart(Stock, datevar="Date", numvar="Value", idvar="Device", titlevar="Title", annotationvar="Annotation", options=list(displayAnnotations=TRUE, width=600, height=350, scaleColumns='[0,1]', scaleType='allmaximized') ) plot(A2) ## Colouring the area below the lines to create an area chart A3 <- 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(A3) ## Data with POSIXct datetime variable A4 <- gvisAnnotationChart(Andrew, datevar="Date/Time UTC", numvar="Pressure_mb", options=list(scaleType='maximized') ) plot(A4) # Change background to blue A5 <- gvisAnnotationChart(Stock, datevar="Date", numvar="Value", idvar="Device", titlevar="Title", annotationvar="Annotation", options=list( displayAnnotations=TRUE, chart = "{chartArea:{backgroundColor:'#003b70'}}", legendPosition='newRow', width=600, height=350)) plot(A5)
The gvisAreaChart function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page.
gvisAreaChart(data, xvar = "", yvar = "", options = list(), chartid)
gvisAreaChart(data, xvar = "", yvar = "", options = list(), chartid)
data |
a |
xvar |
name of the character column which contains the category labels for the x-axes. |
yvar |
a vector of column names of the numerical variables to be plotted. Each column is displayed as a separate line. |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/areachart#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
The area chart is rendered within the browser using SVG or VML and displays tips when hovering over points.
gvisAreaChart returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/areachart
See also print.gvis
, plot.gvis
for
printing and plotting methods
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. df=data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32)) ## Area chart Area1 <- gvisAreaChart(df, xvar="country", yvar=c("val1", "val2")) plot(Area1) ## Stacked chart Area2 <- gvisAreaChart(df, xvar="country", yvar=c("val1", "val2"), options=list(isStacked=TRUE)) plot(Area2) ## Add a customised title Area3 <- gvisAreaChart(df, xvar="country", yvar=c("val1", "val2"), options=list(title="Hello World", titleTextStyle="{color:'red',fontName:'Courier',fontSize:16}")) plot(Area3) ## Not run: ## Change y-axis to percentages Area3 <- gvisAreaChart(df, xvar="country", yvar=c("val1", "val2"), options=list(vAxis="{format:'#,###%'}")) plot(Area3) ## End(Not run)
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. df=data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32)) ## Area chart Area1 <- gvisAreaChart(df, xvar="country", yvar=c("val1", "val2")) plot(Area1) ## Stacked chart Area2 <- gvisAreaChart(df, xvar="country", yvar=c("val1", "val2"), options=list(isStacked=TRUE)) plot(Area2) ## Add a customised title Area3 <- gvisAreaChart(df, xvar="country", yvar=c("val1", "val2"), options=list(title="Hello World", titleTextStyle="{color:'red',fontName:'Courier',fontSize:16}")) plot(Area3) ## Not run: ## Change y-axis to percentages Area3 <- gvisAreaChart(df, xvar="country", yvar=c("val1", "val2"), options=list(vAxis="{format:'#,###%'}")) plot(Area3) ## End(Not run)
The gvisBarChart function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page. The actual chart is rendered by the web browser using SVG or VML.
gvisBarChart(data, xvar = "", yvar = "", options = list(), chartid)
gvisBarChart(data, xvar = "", yvar = "", options = list(), chartid)
data |
a |
xvar |
name of the character column which contains the category labels for the x-axes. |
yvar |
a vector of column names of the numerical variables to be plotted. Each column is displayed as a separate bar/column. |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/barchart#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
gvisBarChart returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/barchart
See also print.gvis
, plot.gvis
for
printing and plotting methods
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. df <- data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32)) ## Bar chart Bar1 <- gvisBarChart(df, xvar="country", yvar=c("val1", "val2")) plot(Bar1) ## Stacked bar chart Bar2 <- gvisBarChart(df, xvar="country", yvar=c("val1", "val2"), options=list(isStacked=TRUE)) plot(Bar2) ## Add a customised title and change width of bars Bar3 <- gvisBarChart(df, xvar="country", yvar=c("val1", "val2"), options=list(title="Hello World", titleTextStyle="{color:'red',fontName:'Courier',fontSize:16}", bar="{groupWidth:'100%'}")) plot(Bar3) ## Not run: ## Change x-axis to percentages Bar4 <- gvisBarChart(df, xvar="country", yvar=c("val1", "val2"), options=list(hAxis="{format:'#,###%'}")) plot(Bar4) ## The following example reads data from a Wikipedia table and displays ## the information in a bar chart. ## We use the readHMLTable function of the XML package to get the data library(XML) ## Get the data of the biggest ISO container companies from Wikipedia ##(table 3): df=readHTMLTable(readLines("https://en.wikipedia.org/wiki/Intermodal_freight_transport"))[[3]][,1:2] ## Rename the second column names(df)[2]="TEU capacity" ## The numbers are displayed with commas to separate thousands, so let's ## get rid of them: df[,2]=as.numeric(gsub(",", "", as.character(df[,2]))) ## Finally we can create a nice bar chart: Bar5 <- gvisBarChart(df, options=list( chartArea="{left:250,top:50,width:\"50%\",height:\"75%\"}", legend="bottom", title="Top 20 container shipping companies in order of TEU capacity")) plot(Bar5) ## End(Not run)
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. df <- data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32)) ## Bar chart Bar1 <- gvisBarChart(df, xvar="country", yvar=c("val1", "val2")) plot(Bar1) ## Stacked bar chart Bar2 <- gvisBarChart(df, xvar="country", yvar=c("val1", "val2"), options=list(isStacked=TRUE)) plot(Bar2) ## Add a customised title and change width of bars Bar3 <- gvisBarChart(df, xvar="country", yvar=c("val1", "val2"), options=list(title="Hello World", titleTextStyle="{color:'red',fontName:'Courier',fontSize:16}", bar="{groupWidth:'100%'}")) plot(Bar3) ## Not run: ## Change x-axis to percentages Bar4 <- gvisBarChart(df, xvar="country", yvar=c("val1", "val2"), options=list(hAxis="{format:'#,###%'}")) plot(Bar4) ## The following example reads data from a Wikipedia table and displays ## the information in a bar chart. ## We use the readHMLTable function of the XML package to get the data library(XML) ## Get the data of the biggest ISO container companies from Wikipedia ##(table 3): df=readHTMLTable(readLines("https://en.wikipedia.org/wiki/Intermodal_freight_transport"))[[3]][,1:2] ## Rename the second column names(df)[2]="TEU capacity" ## The numbers are displayed with commas to separate thousands, so let's ## get rid of them: df[,2]=as.numeric(gsub(",", "", as.character(df[,2]))) ## Finally we can create a nice bar chart: Bar5 <- gvisBarChart(df, options=list( chartArea="{left:250,top:50,width:\"50%\",height:\"75%\"}", legend="bottom", title="Top 20 container shipping companies in order of TEU capacity")) plot(Bar5) ## End(Not run)
The gvisBubbleChart function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page.
gvisBubbleChart( data, idvar = "", xvar = "", yvar = "", colorvar = "", sizevar = "", options = list(), chartid )
gvisBubbleChart( data, idvar = "", xvar = "", yvar = "", colorvar = "", sizevar = "", options = list(), chartid )
data |
a |
idvar |
column name of |
xvar |
column name of a numerical vector in |
yvar |
column name of a numerical vector in |
colorvar |
column name of data that identifies bubbles in the same
series. Use the same value to identify all bubbles that belong to the same
series; bubbles in the same series will be assigned the same color. Series
can be configured using the |
sizevar |
values in this column are mapped to actual pixel values using
the |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/bubblechart#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
A bubble chart is used to visualize a data set with 2 to 4 dimensions. The first two dimensions are visualized as coordinates, the 3rd as color and the 4th as size.
The bubble chart is rendered within the browser using SVG or VML and displays tips when hovering over points.
gvisBubbleChart returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/bubblechart
See also gvisMotionChart
for a moving bubble chart
over time, and print.gvis
, plot.gvis
for
printing and plotting methods.
bubble1 <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales", yvar="Expenses") plot(bubble1) ## Set color and size bubble2 <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales", yvar="Expenses", colorvar="Location", sizevar="Profit", options=list(hAxis='{minValue:75, maxValue:125}')) plot(bubble2) ## Use year to color the bubbles bubble3 <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales", yvar="Expenses", colorvar="Year", sizevar="Profit", options=list(hAxis='{minValue:75, maxValue:125}')) plot(bubble3) ## Gradient colour example bubble4 <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales", yvar="Expenses", sizevar="Profit", options=list(hAxis='{minValue:75, maxValue:125}', colorAxis="{colors: ['lightblue', 'blue']}")) plot(bubble4) ## Not run: ## Moving bubble chart over time, aka motion chart M <- gvisMotionChart(Fruits, Fruit, Year) plot(M) ## End(Not run)
bubble1 <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales", yvar="Expenses") plot(bubble1) ## Set color and size bubble2 <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales", yvar="Expenses", colorvar="Location", sizevar="Profit", options=list(hAxis='{minValue:75, maxValue:125}')) plot(bubble2) ## Use year to color the bubbles bubble3 <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales", yvar="Expenses", colorvar="Year", sizevar="Profit", options=list(hAxis='{minValue:75, maxValue:125}')) plot(bubble3) ## Gradient colour example bubble4 <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales", yvar="Expenses", sizevar="Profit", options=list(hAxis='{minValue:75, maxValue:125}', colorAxis="{colors: ['lightblue', 'blue']}")) plot(bubble4) ## Not run: ## Moving bubble chart over time, aka motion chart M <- gvisMotionChart(Fruits, Fruit, Year) plot(M) ## End(Not run)
A calendar chart is a visualization used to show activity over the course of a long span of time, such as months or years. They're best used when you want to illustrate how some quantity varies depending on the day of the week, or how it trends over time.
gvisCalendar(data, datevar = "", numvar = "", options = list(), chartid)
gvisCalendar(data, datevar = "", numvar = "", options = list(), chartid)
data |
a |
datevar |
column name of |
numvar |
column name of |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/calendar#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
gvisCalendar returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
The calendar chart may be undergoing substantial revisions in future Google Charts releases.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/calendar
See also print.gvis
, plot.gvis
for printing and
plotting methods.
cl1 <- gvisCalendar(Cairo, datevar="Date", numvar="Temp") plot(cl1) ## Not all months shown? ## We can change the setting of the width ... cl2 <- gvisCalendar(Cairo, datevar="Date", numvar="Temp", options=list(width=1000)) plot(cl2) ## ... or the cell size cl3 <- gvisCalendar(Cairo, datevar="Date", numvar="Temp", options=list(calendar="{ cellSize: 10 }")) plot(cl3) ## Example with many options set cl4 <- gvisCalendar(Cairo, datevar="Date", numvar="Temp", options=list( title="Daily temperature in Cairo", height=320, calendar="{yearLabel: { fontName: 'Times-Roman', fontSize: 32, color: '#1A8763', bold: true}, cellSize: 10, cellColor: { stroke: 'red', strokeOpacity: 0.2 }, focusedCellColor: {stroke:'red'}}") ) plot(cl4)
cl1 <- gvisCalendar(Cairo, datevar="Date", numvar="Temp") plot(cl1) ## Not all months shown? ## We can change the setting of the width ... cl2 <- gvisCalendar(Cairo, datevar="Date", numvar="Temp", options=list(width=1000)) plot(cl2) ## ... or the cell size cl3 <- gvisCalendar(Cairo, datevar="Date", numvar="Temp", options=list(calendar="{ cellSize: 10 }")) plot(cl3) ## Example with many options set cl4 <- gvisCalendar(Cairo, datevar="Date", numvar="Temp", options=list( title="Daily temperature in Cairo", height=320, calendar="{yearLabel: { fontName: 'Times-Roman', fontSize: 32, color: '#1A8763', bold: true}, cellSize: 10, cellColor: { stroke: 'red', strokeOpacity: 0.2 }, focusedCellColor: {stroke:'red'}}") ) plot(cl4)
An interactive candlestick chart.
gvisCandlestickChart( data, xvar = "", low = "", open = "", close = "", high = "", options = list(), chartid )
gvisCandlestickChart( data, xvar = "", low = "", open = "", close = "", high = "", options = list(), chartid )
data |
a |
xvar |
name of the character column which contains the category labels for the x-axes. |
low |
name of the numeric column specifying the low/minimum value of this marker. This is the base of the candle's center line. |
open |
name of the numeric column specifying the opening/initial value
of this marker. This is one vertical border of the candle. If less than the
|
close |
name of the numeric column specifying the closing/final value
of this marker. This is the second vertical border of the candle. If less
than the |
high |
name of the numeric column specifying the high/maximum value of this marker. This is the top of the candle's center line. |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/candlestickchart#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
The gvisCandlestickChart function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page. The actual chart is rendered by the web browser using SVG or VML.
A candlestick chart is used to show an opening and closing value overlaid on top of a total variance. Candlestick charts are often used to show stock value behavior. In this chart, items where the opening value is less than the closing value (a gain) are drawn as filled boxes, and items where the opening value is more than the closing value (a loss) are drawn as hollow boxes.
gvisCandlestickChart returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/candlestickchart
See also print.gvis
, plot.gvis
for
printing and plotting methods
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. ## Example data set OpenClose C1 <- gvisCandlestickChart(OpenClose, xvar="Weekday", low="Low", open="Open", close="Close", high="High", options=list(legend='none')) plot(C1)
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. ## Example data set OpenClose C1 <- gvisCandlestickChart(OpenClose, xvar="Weekday", low="Low", open="Open", close="Close", high="High", options=list(legend='none')) plot(C1)
The gvisColumnChart function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page. The actual chart is rendered by the web browser using SVG or VML.
gvisColumnChart(data, xvar = "", yvar = "", options = list(), chartid)
gvisColumnChart(data, xvar = "", yvar = "", options = list(), chartid)
data |
a |
xvar |
name of the character column which contains the category labels for the x-axes. |
yvar |
a vector of column names of the numerical variables to be plotted. Each column is displayed as a separate bar/column. |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/columnchart#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
gvisColumnChart returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/columnchart
See also print.gvis
, plot.gvis
for
printing and plotting methods
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. df=data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32)) ## Column chart Col1 <- gvisColumnChart(df, xvar="country", yvar=c("val1", "val2")) plot(Col1) ## Stacked column chart Col2 <- gvisColumnChart(df, xvar="country", yvar=c("val1", "val2"), options=list(isStacked=TRUE)) plot(Col2) ## Add a customised title and and change width of columns Col3 <- gvisColumnChart(df, xvar="country", yvar=c("val1", "val2"), options=list(title="Hello World", titleTextStyle="{color:'red',fontName:'Courier',fontSize:16}", bar="{groupWidth:'100%'}")) plot(Col3) ## Not run: ## Change y-axis to percentages Col4 <- gvisColumnChart(df, xvar="country", yvar=c("val1", "val2"), options=list(vAxis="{format:'#,###%'}")) plot(Col4) ## End(Not run)
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. df=data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32)) ## Column chart Col1 <- gvisColumnChart(df, xvar="country", yvar=c("val1", "val2")) plot(Col1) ## Stacked column chart Col2 <- gvisColumnChart(df, xvar="country", yvar=c("val1", "val2"), options=list(isStacked=TRUE)) plot(Col2) ## Add a customised title and and change width of columns Col3 <- gvisColumnChart(df, xvar="country", yvar=c("val1", "val2"), options=list(title="Hello World", titleTextStyle="{color:'red',fontName:'Courier',fontSize:16}", bar="{groupWidth:'100%'}")) plot(Col3) ## Not run: ## Change y-axis to percentages Col4 <- gvisColumnChart(df, xvar="country", yvar=c("val1", "val2"), options=list(vAxis="{format:'#,###%'}")) plot(Col4) ## End(Not run)
A chart that lets you render each series as a different marker type from the following list: columns, lines, and area lines.
gvisComboChart(data, xvar = "", yvar = "", options = list(), chartid)
gvisComboChart(data, xvar = "", yvar = "", options = list(), chartid)
data |
a |
xvar |
name of the character column which contains the category labels for the x-axes. |
yvar |
a vector of column names of the numerical variables to be plotted. Each column is displayed as a separate column, line or area series. |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/combochart#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
The gvisComboChart function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page. The actual chart is rendered by the web browser using SVG or VML.
gvisComboChart returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/combochart
See also print.gvis
, plot.gvis
for
printing and plotting methods
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. CityPopularity ## Add the mean CityPopularity$Mean=mean(CityPopularity$Popularity) C1 <- gvisComboChart(CityPopularity, xvar="City", yvar=c("Mean", "Popularity"), options=list(seriesType="bars", title="City Popularity", series='{0: {type:"line"}}')) plot(C1) ## Changing the width of columsn C2 <- gvisComboChart(CityPopularity, xvar="City", yvar=c("Mean", "Popularity"), options=list(seriesType="bars", bar="{groupWidth:'100%'}", title="City Popularity", series='{0: {type:"line"}}')) plot(C2)
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. CityPopularity ## Add the mean CityPopularity$Mean=mean(CityPopularity$Popularity) C1 <- gvisComboChart(CityPopularity, xvar="City", yvar=c("Mean", "Popularity"), options=list(seriesType="bars", title="City Popularity", series='{0: {type:"line"}}')) plot(C1) ## Changing the width of columsn C2 <- gvisComboChart(CityPopularity, xvar="City", yvar=c("Mean", "Popularity"), options=list(seriesType="bars", bar="{groupWidth:'100%'}", title="City Popularity", series='{0: {type:"line"}}')) plot(C2)
A Gantt chart is a type of chart that illustrates the breakdown of a project into its component tasks.
gvisGantt( data, taskID = "", taskName = "", resource = "", start = "", end = "", duration = "", percentComplete = "", dependencies = "", options = list(), chartid )
gvisGantt( data, taskID = "", taskName = "", resource = "", start = "", end = "", duration = "", percentComplete = "", dependencies = "", options = list(), chartid )
data |
data.frame that contains the data to be visualised |
taskID |
a string that refers to the column name in
|
taskName |
a string that refers to the column name in
|
resource |
a string that refers to the column name in
|
start |
a string that refers to the date column name in
|
end |
a string that refers to the date column name in
|
duration |
a string that refers to the numeric column name in
|
percentComplete |
a string that refers to the numeric column name in
|
dependencies |
a string that refers to the column name in
|
options |
list of configuration options. The options are documented in detail by Google online: https://developers.google.com/chart/interactive/docs/gallery/ganttchart#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
gvisGantt returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/ganttchart
# Helper function to generate example data daysToMilliseconds <- function(days){ days * 24 * 60 * 60 * 1000 } dat <- data.frame( taskID = c("Research", "Write", "Cite", "Complete", "Outline"), taskName = c("Find sources", "Write Paper", "Create bibliography", "Hand in paper", "Outline paper"), resource = c(NA, "write", "write", "complete", "write"), start = c(as.Date("2015-01-01"), NA, NA, NA, NA), end = as.Date(c("2015-01-05", "2015-01-09", "2015-01-07", "2015-01-10", "2015-01-06")), duration = c(NA, daysToMilliseconds(c(3, 1, 1, 1))), percentComplete = c(100, 25, 20, 0, 100), dependencies = c(NA, "Research, Outline", "Research", "Cite, Write", "Research") ) gntt1 <- gvisGantt(dat, taskID = "taskID", taskName = "taskName", resource = "resource", start = "start", end = "end", duration = "duration", percentComplete = "percentComplete", dependencies = "dependencies") plot(gntt1) ## gantt chart with options set gntt2 <- gvisGantt(dat, taskID = "taskID", taskName = "taskName", resource = "resource", start = "start", end = "end", duration = "duration", percentComplete = "percentComplete", dependencies = "dependencies", options = list( height = 275, gantt = "{ criticalPathEnabled: true, innerGridHorizLine: { stroke: '#ffe0b2', strokeWidth: 2 }, innerGridTrack: {fill: '#fff3e0'}, innerGridDarkTrack: {fill: '#ffcc80'}, labelStyle: { fontName: 'Arial', fontSize: 14 }}" )) plot(gntt2) # Example with date time dat <- data.frame( taskID = c("Research", "Write", "Complete"), taskName = c("Find sources", "Write Paper", "Hand in paper"), resource = c(NA, "write", "complete"), start = c(as.POSIXct("2015-01-01 6:00:00"), NA, NA), end = as.POSIXct(c("2015-01-01 8:00:00", "2015-01-01 13:30:00", "2015-01-01 20:30:00")), duration = c(NA, daysToMilliseconds(c(.1, .05))), percentComplete = c(100, 25, 0), dependencies = c(NA, "Research", "Write")) gntt3 <- gvisGantt(dat, taskID = "taskID", taskName = "taskName", resource = "resource", start = "start", end = "end", duration = "duration", percentComplete = "percentComplete", dependencies = "dependencies") plot(gntt3)
# Helper function to generate example data daysToMilliseconds <- function(days){ days * 24 * 60 * 60 * 1000 } dat <- data.frame( taskID = c("Research", "Write", "Cite", "Complete", "Outline"), taskName = c("Find sources", "Write Paper", "Create bibliography", "Hand in paper", "Outline paper"), resource = c(NA, "write", "write", "complete", "write"), start = c(as.Date("2015-01-01"), NA, NA, NA, NA), end = as.Date(c("2015-01-05", "2015-01-09", "2015-01-07", "2015-01-10", "2015-01-06")), duration = c(NA, daysToMilliseconds(c(3, 1, 1, 1))), percentComplete = c(100, 25, 20, 0, 100), dependencies = c(NA, "Research, Outline", "Research", "Cite, Write", "Research") ) gntt1 <- gvisGantt(dat, taskID = "taskID", taskName = "taskName", resource = "resource", start = "start", end = "end", duration = "duration", percentComplete = "percentComplete", dependencies = "dependencies") plot(gntt1) ## gantt chart with options set gntt2 <- gvisGantt(dat, taskID = "taskID", taskName = "taskName", resource = "resource", start = "start", end = "end", duration = "duration", percentComplete = "percentComplete", dependencies = "dependencies", options = list( height = 275, gantt = "{ criticalPathEnabled: true, innerGridHorizLine: { stroke: '#ffe0b2', strokeWidth: 2 }, innerGridTrack: {fill: '#fff3e0'}, innerGridDarkTrack: {fill: '#ffcc80'}, labelStyle: { fontName: 'Arial', fontSize: 14 }}" )) plot(gntt2) # Example with date time dat <- data.frame( taskID = c("Research", "Write", "Complete"), taskName = c("Find sources", "Write Paper", "Hand in paper"), resource = c(NA, "write", "complete"), start = c(as.POSIXct("2015-01-01 6:00:00"), NA, NA), end = as.POSIXct(c("2015-01-01 8:00:00", "2015-01-01 13:30:00", "2015-01-01 20:30:00")), duration = c(NA, daysToMilliseconds(c(.1, .05))), percentComplete = c(100, 25, 0), dependencies = c(NA, "Research", "Write")) gntt3 <- gvisGantt(dat, taskID = "taskID", taskName = "taskName", resource = "resource", start = "start", end = "end", duration = "duration", percentComplete = "percentComplete", dependencies = "dependencies") plot(gntt3)
The gvisGauge function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page. The actual chart is rendered by the web browser using SVG or VML.
gvisGauge(data, labelvar = "", numvar = "", options = list(), chartid)
gvisGauge(data, labelvar = "", numvar = "", options = list(), chartid)
data |
a |
labelvar |
name of the character column which contains the category labels for the slice labels. |
numvar |
a vector of column names of the numerical variables of the slice values. |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/gauge#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
gvisGauge returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/gauge
See also print.gvis
, plot.gvis
for
printing and plotting methods
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. Gauge1 <- gvisGauge(CityPopularity, options=list(min=0, max=800, greenFrom=500, greenTo=800, yellowFrom=300, yellowTo=500, redFrom=0, redTo=300)) plot(Gauge1)
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. Gauge1 <- gvisGauge(CityPopularity, options=list(min=0, max=800, greenFrom=500, greenTo=800, yellowFrom=300, yellowTo=500, redFrom=0, redTo=300)) plot(Gauge1)
The gvisGeoChart function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page.
gvisGeoChart( data, locationvar = "", colorvar = "", sizevar = "", hovervar = "", options = list(), chartid )
gvisGeoChart( data, locationvar = "", colorvar = "", sizevar = "", hovervar = "", options = list(), chartid )
data |
a |
locationvar |
column name of
|
colorvar |
column name of |
sizevar |
only used for |
hovervar |
column name of |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/geochart#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
A geo chart is a map of a country, a continent, or a region with two modes: The region mode colorizes whole regions, such as countries, provinces, or states. The marker mode marks designated regions using bubbles that are scaled according to a value that you specify.
A geo chart is rendered within the browser using SVG or VML. Note that the map is not scrollable or draggable.
gvisGeoChart returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected], Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/geochart
See also print.gvis
, plot.gvis
for printing and plotting methods.
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. ## Regions examples ## The regions style fills entire regions (typically countries) with ## colors corresponding to the values that you assign G1a <- gvisGeoChart(Exports, locationvar='Country', colorvar='Profit') plot(G1a) ## Change projection G1b <- gvisGeoChart(Exports, locationvar='Country', colorvar='Profit', options=list(projection="kavrayskiy-vii")) plot(G1b) ## Plot only Europe G2 <- gvisGeoChart(Exports, "Country", "Profit", options=list(region="150")) plot(G2) ## Example showing US data by state require(datasets) states <- data.frame(state.name, state.x77) G3 <- gvisGeoChart(states, "state.name", "Illiteracy", options=list(region="US", displayMode="regions", resolution="provinces", width=600, height=400)) plot(G3) G4 <- gvisGeoChart(Andrew, "LatLong", colorvar='Speed_kt', options=list(region="US")) plot(G4) G5 <- gvisGeoChart(Andrew, "LatLong", sizevar='Speed_kt', colorvar="Pressure_mb", options=list(region="US")) plot(G5) ## Create lat:long values and plot a map of Oceania ## Set background colour to light-blue require(stats) data(quakes) head(quakes) quakes$latlong<-paste(quakes$lat, quakes$long, sep=":") G6 <- gvisGeoChart(quakes, "latlong", "depth", "mag", options=list(displayMode="Markers", region="009", colorAxis="{colors:['red', 'grey']}", backgroundColor="lightblue")) plot(G6)
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. ## Regions examples ## The regions style fills entire regions (typically countries) with ## colors corresponding to the values that you assign G1a <- gvisGeoChart(Exports, locationvar='Country', colorvar='Profit') plot(G1a) ## Change projection G1b <- gvisGeoChart(Exports, locationvar='Country', colorvar='Profit', options=list(projection="kavrayskiy-vii")) plot(G1b) ## Plot only Europe G2 <- gvisGeoChart(Exports, "Country", "Profit", options=list(region="150")) plot(G2) ## Example showing US data by state require(datasets) states <- data.frame(state.name, state.x77) G3 <- gvisGeoChart(states, "state.name", "Illiteracy", options=list(region="US", displayMode="regions", resolution="provinces", width=600, height=400)) plot(G3) G4 <- gvisGeoChart(Andrew, "LatLong", colorvar='Speed_kt', options=list(region="US")) plot(G4) G5 <- gvisGeoChart(Andrew, "LatLong", sizevar='Speed_kt', colorvar="Pressure_mb", options=list(region="US")) plot(G5) ## Create lat:long values and plot a map of Oceania ## Set background colour to light-blue require(stats) data(quakes) head(quakes) quakes$latlong<-paste(quakes$lat, quakes$long, sep=":") G6 <- gvisGeoChart(quakes, "latlong", "depth", "mag", options=list(displayMode="Markers", region="009", colorAxis="{colors:['red', 'grey']}", backgroundColor="lightblue")) plot(G6)
The gvisGeoMap function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page.
A geo map is a map of a country, continent, or region map, with colours and values assigned to specific regions. Values are displayed as a colour scale, and you can specify optional hover-text for regions. The map is rendered in the browser. Note that the map is not scroll-able or drag-gable, but can be configured to allow zooming.
gvisGeoMap( data, locationvar = "", numvar = "", hovervar = "", options = list(), chartid )
gvisGeoMap( data, locationvar = "", numvar = "", hovervar = "", options = list(), chartid )
data |
|
locationvar |
column name of
|
numvar |
column name of |
hovervar |
column name of |
options |
list of configuration options. The options are documented in detail by Google online: https://developers.google.com/chart/interactive/docs/gallery/geomap#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
gvisGeoMap returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
GeoMap (gvisGeoMap) is Flash based, conisder using GeoChart (gvisGeoChart) instead. For more details visit: goo.gl/tkiEV8
Because of Flash security settings the chart might not work correctly when accessed from a file location in the browser (e.g., file:///c:/webhost/myhost/myviz.html) rather than from a web server URL (e.g. https://www.myhost.com/myviz.html). See the googleVis package vignette and the Macromedia web site (https://www.macromedia.com/support/documentation/en/flashplayer/help/) for more details.
Markus Gesmann [email protected], Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/geomap
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. ## Regions Example ## The regions style fills entire regions (typically countries) with colors ## corresponding to the values that you assign. Specify the regions style ## by assigning options['dataMode'] = 'regions' in your code. G1 <- gvisGeoMap(Exports, locationvar='Country', numvar='Profit', options=list(dataMode="regions")) plot(G1) ## Markers Example ## The "markers" style displays a circle, sized and colored to indicate ## a value, over the regions that you specify. G2 <- gvisGeoMap(CityPopularity, locationvar='City', numvar='Popularity', options=list(region='US', height=350, dataMode='markers', colors='[0xFF8747, 0xFFB581, 0xc06000]')) plot(G2) ## Example showing US data by state require(datasets) states <- data.frame(state.name, state.x77) G3 <- gvisGeoMap(states, "state.name", "Illiteracy", options=list(region="US", dataMode="regions", width=600, height=400)) plot(G3) ## Example with latitude and longitude information ## Show Hurricane Andrew (1992) storm track G4 <- gvisGeoMap(Andrew, locationvar="LatLong", numvar="Speed_kt", hovervar="Category", options=list(height=350, region="US", dataMode="markers")) plot(G4) ## World population WorldPopulation=data.frame(Country=Population$Country, Population.in.millions=round(Population$Population/1e6,0), Rank=paste(Population$Country, "Rank:", Population$Rank)) G5 <- gvisGeoMap(WorldPopulation, "Country", "Population.in.millions", "Rank", options=list(dataMode="regions", width=600, height=300)) plot(G5)
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. ## Regions Example ## The regions style fills entire regions (typically countries) with colors ## corresponding to the values that you assign. Specify the regions style ## by assigning options['dataMode'] = 'regions' in your code. G1 <- gvisGeoMap(Exports, locationvar='Country', numvar='Profit', options=list(dataMode="regions")) plot(G1) ## Markers Example ## The "markers" style displays a circle, sized and colored to indicate ## a value, over the regions that you specify. G2 <- gvisGeoMap(CityPopularity, locationvar='City', numvar='Popularity', options=list(region='US', height=350, dataMode='markers', colors='[0xFF8747, 0xFFB581, 0xc06000]')) plot(G2) ## Example showing US data by state require(datasets) states <- data.frame(state.name, state.x77) G3 <- gvisGeoMap(states, "state.name", "Illiteracy", options=list(region="US", dataMode="regions", width=600, height=400)) plot(G3) ## Example with latitude and longitude information ## Show Hurricane Andrew (1992) storm track G4 <- gvisGeoMap(Andrew, locationvar="LatLong", numvar="Speed_kt", hovervar="Category", options=list(height=350, region="US", dataMode="markers")) plot(G4) ## World population WorldPopulation=data.frame(Country=Population$Country, Population.in.millions=round(Population$Population/1e6,0), Rank=paste(Population$Country, "Rank:", Population$Rank)) G5 <- gvisGeoMap(WorldPopulation, "Country", "Population.in.millions", "Rank", options=list(dataMode="regions", width=600, height=300)) plot(G5)
The gvisHistogram function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page. The actual chart is rendered by the web browser using SVG or VML.
gvisHistogram(data, options = list(), chartid)
gvisHistogram(data, options = list(), chartid)
data |
a |
options |
list of configuration options, see https://developers.google.com/chart/interactive/docs/gallery/histogram#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
gvisHistogram returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/histogram
See also print.gvis
, plot.gvis
for
printing and plotting methods
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. hist1 <- gvisHistogram(dino) plot(hist1) ## Histogram of the top 20 countries pop <- Population[1:20,c("Country", "Population")] pop=transform(pop, Population=round(Population/1e6)) hist2 <- gvisHistogram(pop, option=list(title="Country Populations", legend="{ position: 'none' }", colors="['green']")) plot(hist2) set.seed(123) dat=data.frame(A=rpois(100, 20), B=rpois(100, 5), C=rpois(100, 50)) hist3 <- gvisHistogram(dat, options=list( legend="{ position: 'top', maxLines: 2 }", colors="['#5C3292', '#1A8763', '#871B47']")) plot(hist3)
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. hist1 <- gvisHistogram(dino) plot(hist1) ## Histogram of the top 20 countries pop <- Population[1:20,c("Country", "Population")] pop=transform(pop, Population=round(Population/1e6)) hist2 <- gvisHistogram(pop, option=list(title="Country Populations", legend="{ position: 'none' }", colors="['green']")) plot(hist2) set.seed(123) dat=data.frame(A=rpois(100, 20), B=rpois(100, 5), C=rpois(100, 50)) hist3 <- gvisHistogram(dat, options=list( legend="{ position: 'top', maxLines: 2 }", colors="['#5C3292', '#1A8763', '#871B47']")) plot(hist3)
The gvisLineChart function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page. The actual chart is rendered by the web browser using SVG or VML.
gvisLineChart(data, xvar = "", yvar = "", options = list(), chartid)
gvisLineChart(data, xvar = "", yvar = "", options = list(), chartid)
data |
a |
xvar |
name of the character column which contains the category labels for the x-axes. |
yvar |
a vector of column names of the numerical variables to be plotted. Each column is displayed as a separate line. |
options |
list of configuration options, see https://developers.google.com/chart/interactive/docs/gallery/linechart#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
gvisLineChart returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/linechart
See also print.gvis
, plot.gvis
for
printing and plotting methods
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. df <- data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32)) ## Line chart Line1 <- gvisLineChart(df, xvar="country", yvar=c("val1", "val2")) plot(Line1) ## Add a customised title and smoothed curve Line2 <- gvisLineChart(df, xvar="country", yvar=c("val1", "val2"), options=list(title="Hello World", titleTextStyle="{color:'red',fontName:'Courier',fontSize:16}", curveType='function')) plot(Line2) ## Not run: ## Change y-axis to percentages Line3 <- gvisLineChart(df, xvar="country", yvar=c("val1", "val2"), options=list(vAxis="{format:'#,###%'}")) plot(Line3) ## End(Not run) ## Create a chart with two y-axis: Line4 <- gvisLineChart(df, "country", c("val1","val2"), options=list(series="[{targetAxisIndex: 0}, {targetAxisIndex:1}]", vAxes="[{title:'val1'}, {title:'val2'}]" )) plot(Line4) ## Line chart with edit button Line5 <- gvisLineChart(df, xvar="country", yvar=c("val1", "val2"), options=list(gvis.editor="Edit me!")) plot(Line5) ## Customizing lines Dashed <- gvisLineChart(df, xvar="country", yvar=c("val1","val2"), options=list( series="[{color:'green', targetAxisIndex: 0, lineWidth: 1, lineDashStyle: [2, 2, 20, 2, 20, 2]}, {color: 'blue',targetAxisIndex: 1, lineWidth: 2, lineDashStyle: [4, 1]}]", vAxes="[{title:'val1'}, {title:'val2'}]" )) plot(Dashed)
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. df <- data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32)) ## Line chart Line1 <- gvisLineChart(df, xvar="country", yvar=c("val1", "val2")) plot(Line1) ## Add a customised title and smoothed curve Line2 <- gvisLineChart(df, xvar="country", yvar=c("val1", "val2"), options=list(title="Hello World", titleTextStyle="{color:'red',fontName:'Courier',fontSize:16}", curveType='function')) plot(Line2) ## Not run: ## Change y-axis to percentages Line3 <- gvisLineChart(df, xvar="country", yvar=c("val1", "val2"), options=list(vAxis="{format:'#,###%'}")) plot(Line3) ## End(Not run) ## Create a chart with two y-axis: Line4 <- gvisLineChart(df, "country", c("val1","val2"), options=list(series="[{targetAxisIndex: 0}, {targetAxisIndex:1}]", vAxes="[{title:'val1'}, {title:'val2'}]" )) plot(Line4) ## Line chart with edit button Line5 <- gvisLineChart(df, xvar="country", yvar=c("val1", "val2"), options=list(gvis.editor="Edit me!")) plot(Line5) ## Customizing lines Dashed <- gvisLineChart(df, xvar="country", yvar=c("val1","val2"), options=list( series="[{color:'green', targetAxisIndex: 0, lineWidth: 1, lineDashStyle: [2, 2, 20, 2, 20, 2]}, {color: 'blue',targetAxisIndex: 1, lineWidth: 2, lineDashStyle: [4, 1]}]", vAxes="[{title:'val1'}, {title:'val2'}]" )) plot(Dashed)
The gvisMap function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page.
gvisMap(data, locationvar = "", tipvar = "", options = list(), chartid)
gvisMap(data, locationvar = "", tipvar = "", options = list(), chartid)
data |
a |
locationvar |
column name of
|
tipvar |
column name of |
options |
list of configuration options for Google Map. https://developers.google.com/chart/interactive/docs/gallery/map#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
The maps are the well known Google Maps.
gvisMap returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/map
See also print.gvis
, plot.gvis
for printing and
plotting methods, gvisGeoChart
for an alternative to gvisMap
.
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. ## Example with latitude and longitude information ## Plot Hurricane Andrew (1992) storm path: data(Andrew) M1 <- gvisMap(Andrew, "LatLong" , "Tip", options=list(showTip=TRUE, showLine=TRUE, enableScrollWheel=TRUE, mapType='hybrid', useMapTypeControl=TRUE, width=800,height=400)) plot(M1) ## Example with address, here UK post-code and some html code in tooltip df <- data.frame(Postcode=c("EC3M 7HA", "EC2P 2EJ"), Tip=c("<a href='https://www.lloyds.com'>Lloyd's</a>", "<a href='https://www.guildhall.cityoflondon.gov.uk/'>Guildhall</a>")) M2 <- gvisMap(df, "Postcode", "Tip", options=list(showTip=TRUE, mapType='normal', enableScrollWheel=TRUE)) plot(M2) ## Change mapping icons M3 <- gvisMap(df, "Postcode", "Tip", options=list(showTip=TRUE, mapType='normal', enableScrollWheel=TRUE, icons=paste0("{", "'default': {'normal': 'https://icons.iconarchive.com/", "icons/icons-land/vista-map-markers/48/", "Map-Marker-Ball-Azure-icon.png',\n", "'selected': 'https://icons.iconarchive.com/", "icons/icons-land/vista-map-markers/48/", "Map-Marker-Ball-Right-Azure-icon.png'", "}}"))) plot(M3)
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. ## Example with latitude and longitude information ## Plot Hurricane Andrew (1992) storm path: data(Andrew) M1 <- gvisMap(Andrew, "LatLong" , "Tip", options=list(showTip=TRUE, showLine=TRUE, enableScrollWheel=TRUE, mapType='hybrid', useMapTypeControl=TRUE, width=800,height=400)) plot(M1) ## Example with address, here UK post-code and some html code in tooltip df <- data.frame(Postcode=c("EC3M 7HA", "EC2P 2EJ"), Tip=c("<a href='https://www.lloyds.com'>Lloyd's</a>", "<a href='https://www.guildhall.cityoflondon.gov.uk/'>Guildhall</a>")) M2 <- gvisMap(df, "Postcode", "Tip", options=list(showTip=TRUE, mapType='normal', enableScrollWheel=TRUE)) plot(M2) ## Change mapping icons M3 <- gvisMap(df, "Postcode", "Tip", options=list(showTip=TRUE, mapType='normal', enableScrollWheel=TRUE, icons=paste0("{", "'default': {'normal': 'https://icons.iconarchive.com/", "icons/icons-land/vista-map-markers/48/", "Map-Marker-Ball-Azure-icon.png',\n", "'selected': 'https://icons.iconarchive.com/", "icons/icons-land/vista-map-markers/48/", "Map-Marker-Ball-Right-Azure-icon.png'", "}}"))) plot(M3)
gvisMerge merges two gvis-objects, either next or below each other into one gvis-object. The objects are arranged in a HTML table.
gvisMerge(x, y, horizontal = FALSE, tableOptions = "border=\"0\"", chartid)
gvisMerge(x, y, horizontal = FALSE, tableOptions = "border=\"0\"", chartid)
x |
a |
y |
a |
horizontal |
boolean. Default |
tableOptions |
a valid HTML table option string. Default |
chartid |
character. If missing (default) a random chart id will be generated based on
chart type and |
gvisMerge
returns list of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the following components:
type |
Google visualisation type, here 'gvisMerge' |
chartid |
character id of the chart object. Unique chart ids are required to place several charts on the same page. |
html |
a list with the building blocks for a page
|
Markus Gesmann [email protected],
Google Chart Tools API: https://developers.google.com/chart/
Follow the link for Google's data policy.
See also print.gvis
, plot.gvis
for
printing and plotting methods
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. Pie1 <- gvisPieChart(CityPopularity) ## Doughnut chart - a pie with a hole Pie2 <- gvisPieChart(CityPopularity, options=list( slices="{4: {offset: 0.2}, 0: {offset: 0.3}}", title='City popularity', legend='none', pieSliceText='label', pieHole=0.5)) plot(gvisMerge(Pie2, Pie1, tableOptions = "cellspacing=\"20\" bgcolor=\"#AABBCC\"", horizontal=TRUE)) ## Nested charts G <- gvisGeoChart(Exports, "Country", "Profit", options=list(width=250, height=100)) T <- gvisTable(Exports, options=list(width=250, height=300)) GT <- gvisMerge(G,T, horizontal=FALSE) plot(GT) M <- gvisMotionChart(Fruits, "Fruit", "Year", options=list(width=400, height=410)) GTM <- gvisMerge(GT, M, horizontal=TRUE, tableOptions="cellspacing=10") plot(GTM) line <- gvisLineChart(OpenClose, "Weekday", c("Open", "Close"), options=list(legend='none', width=300, height=150)) column <- gvisColumnChart(OpenClose, "Weekday", c("Open", "Close"), options=list(legend='none', width=300, height=150)) area <- gvisAreaChart(OpenClose, "Weekday", c("Open", "Close"), options=list(legend='none', width=300, height=150)) bar <- gvisBarChart(OpenClose, "Weekday", c("Open", "Close"), options=list(legend='none', width=300, height=150)) LBCA <- gvisMerge(gvisMerge(line, bar), gvisMerge(column, area), horizontal=TRUE, tableOptions="bgcolor=\"#AABBCC\"") plot(LBCA) ## Applying gvisMerge successively p <- Reduce(gvisMerge, list(line, column, area, bar)) plot(p)
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. Pie1 <- gvisPieChart(CityPopularity) ## Doughnut chart - a pie with a hole Pie2 <- gvisPieChart(CityPopularity, options=list( slices="{4: {offset: 0.2}, 0: {offset: 0.3}}", title='City popularity', legend='none', pieSliceText='label', pieHole=0.5)) plot(gvisMerge(Pie2, Pie1, tableOptions = "cellspacing=\"20\" bgcolor=\"#AABBCC\"", horizontal=TRUE)) ## Nested charts G <- gvisGeoChart(Exports, "Country", "Profit", options=list(width=250, height=100)) T <- gvisTable(Exports, options=list(width=250, height=300)) GT <- gvisMerge(G,T, horizontal=FALSE) plot(GT) M <- gvisMotionChart(Fruits, "Fruit", "Year", options=list(width=400, height=410)) GTM <- gvisMerge(GT, M, horizontal=TRUE, tableOptions="cellspacing=10") plot(GTM) line <- gvisLineChart(OpenClose, "Weekday", c("Open", "Close"), options=list(legend='none', width=300, height=150)) column <- gvisColumnChart(OpenClose, "Weekday", c("Open", "Close"), options=list(legend='none', width=300, height=150)) area <- gvisAreaChart(OpenClose, "Weekday", c("Open", "Close"), options=list(legend='none', width=300, height=150)) bar <- gvisBarChart(OpenClose, "Weekday", c("Open", "Close"), options=list(legend='none', width=300, height=150)) LBCA <- gvisMerge(gvisMerge(line, bar), gvisMerge(column, area), horizontal=TRUE, tableOptions="bgcolor=\"#AABBCC\"") plot(LBCA) ## Applying gvisMerge successively p <- Reduce(gvisMerge, list(line, column, area, bar)) plot(p)
The gvisMotionChart function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page. The actual chart is rendered by the web browser in Flash. A motion chart is a dynamic chart to explore several indicators over time.
gvisMotionChart( data, idvar = "id", timevar = "time", xvar = "", yvar = "", colorvar = "", sizevar = "", date.format = "%Y/%m/%d", options = list(), chartid )
gvisMotionChart( data, idvar = "id", timevar = "time", xvar = "", yvar = "", colorvar = "", sizevar = "", date.format = "%Y/%m/%d", options = list(), chartid )
data |
a |
idvar |
column name of |
timevar |
column name of |
xvar |
column name of a numerical vector in |
yvar |
column name of a numerical vector in |
colorvar |
column name of data that identifies bubbles in the
same series. Use the same value to identify all bubbles that belong
to the same series; bubbles in the same series will be assigned the
same color. Series can be configured using the |
sizevar |
values in this column are mapped to actual pixel
values using the |
date.format |
if |
options |
list of configuration options for Google Motion Chart. The options are documented in detail by Google online: https://developers.google.com/chart/interactive/docs/gallery/motionchart#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
gvisMotionChart returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Because of Flash security settings the chart might not work correctly when accessed from a file location in the browser (e.g., file:///c:/webhost/myhost/myviz.html) rather than from a web server URL (e.g. https://www.myhost.com/myviz.html). See the googleVis package vignette and the Macromedia web site (https://www.macromedia.com/support/documentation/en/flashplayer/help/) for more details.
Please note that a timevar
with values less than 100 will
be shown as years 19xx.
Markus Gesmann [email protected], Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/motionchart
See also print.gvis
, plot.gvis
for printing and plotting methods.
## Please note that by default the googleVis plot command ## will open a browser window and requires Flash and Internet ## connection to display the visualisation. M1 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year") plot(M1) ## Not run: ## Usage of date variable M2 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Date", date.format = "\\%Y\\%m\\%d") plot(M2) ## Display weekly data: M3 <- gvisMotionChart(Fruits, "Fruit", "Date", date.format="\\%YW\\%W") plot(M3) ## End(Not run) ## Options: no side panel on the right M4 <- gvisMotionChart(Fruits,"Fruit", "Year", options=list(showSidePanel=FALSE)) plot(M4) ## Options: trails un-ticked M5 <- gvisMotionChart(Fruits, "Fruit", "Year", options=list(state='{"showTrails":false};')) plot(M5) ## You can change some of displaying settings via the browser, ## e.g. the level of opacity of non-selected items, or the chart type. ## The state string from the 'Advanced' tab can be used to set those ## settings via R. Just copy and past the string from the browser into ## the argument state of the options list. ## Here is an example of a motion chart, with an initial line chart ## displayed. Ensure that you have a newline at the start and end of ## your settings string. myStateSettings <-' {"xZoomedDataMin":1199145600000,"colorOption":"2", "duration":{"timeUnit":"Y","multiplier":1},"yLambda":1, "yAxisOption":"4","sizeOption":"_UNISIZE", "iconKeySettings":[],"xLambda":1,"nonSelectedAlpha":0, "xZoomedDataMax":1262304000000,"iconType":"LINE", "dimensions":{"iconDimensions":["dim0"]}, "showTrails":false,"uniColorForNonSelected":false, "xAxisOption":"_TIME","orderedByX":false,"playDuration":15000, "xZoomedIn":false,"time":"2010","yZoomedDataMin":0, "yZoomedIn":false,"orderedByY":false,"yZoomedDataMax":100} ' M6a <- gvisMotionChart(Fruits, "Fruit", "Year", options=list(state=myStateSettings)) plot(M6a) ## Newline set explicitly myStateSettings <-'\n{"iconType":"LINE"}\n' M6b <- gvisMotionChart(Fruits, "Fruit", "Year", options=list(state=myStateSettings)) plot(M6b) ## Define which columns are used for the initial setup of the various ## dimensions M7 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year", xvar="Profit", yvar="Expenses", colorvar="Location", sizevar="Sales") plot(M7) ## For more information see: ## https://developers.google.com/chart/interactive/docs/gallery/motionchart ## See also the demo(WorldBank). It demonstrates how you can access ## country level data from the World Bank to create Gapminder-like ## plots.
## Please note that by default the googleVis plot command ## will open a browser window and requires Flash and Internet ## connection to display the visualisation. M1 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year") plot(M1) ## Not run: ## Usage of date variable M2 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Date", date.format = "\\%Y\\%m\\%d") plot(M2) ## Display weekly data: M3 <- gvisMotionChart(Fruits, "Fruit", "Date", date.format="\\%YW\\%W") plot(M3) ## End(Not run) ## Options: no side panel on the right M4 <- gvisMotionChart(Fruits,"Fruit", "Year", options=list(showSidePanel=FALSE)) plot(M4) ## Options: trails un-ticked M5 <- gvisMotionChart(Fruits, "Fruit", "Year", options=list(state='{"showTrails":false};')) plot(M5) ## You can change some of displaying settings via the browser, ## e.g. the level of opacity of non-selected items, or the chart type. ## The state string from the 'Advanced' tab can be used to set those ## settings via R. Just copy and past the string from the browser into ## the argument state of the options list. ## Here is an example of a motion chart, with an initial line chart ## displayed. Ensure that you have a newline at the start and end of ## your settings string. myStateSettings <-' {"xZoomedDataMin":1199145600000,"colorOption":"2", "duration":{"timeUnit":"Y","multiplier":1},"yLambda":1, "yAxisOption":"4","sizeOption":"_UNISIZE", "iconKeySettings":[],"xLambda":1,"nonSelectedAlpha":0, "xZoomedDataMax":1262304000000,"iconType":"LINE", "dimensions":{"iconDimensions":["dim0"]}, "showTrails":false,"uniColorForNonSelected":false, "xAxisOption":"_TIME","orderedByX":false,"playDuration":15000, "xZoomedIn":false,"time":"2010","yZoomedDataMin":0, "yZoomedIn":false,"orderedByY":false,"yZoomedDataMax":100} ' M6a <- gvisMotionChart(Fruits, "Fruit", "Year", options=list(state=myStateSettings)) plot(M6a) ## Newline set explicitly myStateSettings <-'\n{"iconType":"LINE"}\n' M6b <- gvisMotionChart(Fruits, "Fruit", "Year", options=list(state=myStateSettings)) plot(M6b) ## Define which columns are used for the initial setup of the various ## dimensions M7 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year", xvar="Profit", yvar="Expenses", colorvar="Location", sizevar="Sales") plot(M7) ## For more information see: ## https://developers.google.com/chart/interactive/docs/gallery/motionchart ## See also the demo(WorldBank). It demonstrates how you can access ## country level data from the World Bank to create Gapminder-like ## plots.
An organizational chart that supports selection.
gvisOrgChart( data, idvar = "", parentvar = "", tipvar = "", options = list(), chartid )
gvisOrgChart( data, idvar = "", parentvar = "", tipvar = "", options = list(), chartid )
data |
a |
idvar |
column name of |
parentvar |
column name of |
tipvar |
column name of |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/orgchart#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
The gvisOrgChart function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page. The actual chart is rendered by the web browser.
gvisOrgChart returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/orgchart
See also print.gvis
, plot.gvis
for printing and
plotting methods.
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. Regions Org1 <- gvisOrgChart(Regions, idvar = "Region", parentvar = "Parent", tipvar="Val") plot(Org1) ## Set a few options Org2 <- gvisOrgChart(Regions, idvar = "Region", parentvar = "Parent", tipvar="Val", options=list(width=600, height=400, size='large', allowCollapse=TRUE)) plot(Org2)
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. Regions Org1 <- gvisOrgChart(Regions, idvar = "Region", parentvar = "Parent", tipvar="Val") plot(Org1) ## Set a few options Org2 <- gvisOrgChart(Regions, idvar = "Region", parentvar = "Parent", tipvar="Val", options=list(width=600, height=400, size='large', allowCollapse=TRUE)) plot(Org2)
The gvisPieChart function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page. The actual chart is rendered by the web browser using SVG or VML.
gvisPieChart(data, labelvar = "", numvar = "", options = list(), chartid)
gvisPieChart(data, labelvar = "", numvar = "", options = list(), chartid)
data |
a |
labelvar |
Name of the character column which contains the category labels for the slice labels. |
numvar |
a vector of column names of the numerical variables of the slice values. |
options |
list of configuration options for Google Pie Charts, see: https://developers.google.com/chart/interactive/docs/gallery/piechart#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
gvisPieChart returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/piechart
See also print.gvis
, plot.gvis
for
printing and plotting methods
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. Pie1 <- gvisPieChart(CityPopularity) plot(Pie1) ## Doughnut chart - a pie with a hole Pie2 <- gvisPieChart(CityPopularity, options=list( slices="{4: {offset: 0.2}, 0: {offset: 0.3}}", title='City popularity', legend='none', pieSliceText='label', pieHole=0.5)) plot(Pie2)
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. Pie1 <- gvisPieChart(CityPopularity) plot(Pie1) ## Doughnut chart - a pie with a hole Pie2 <- gvisPieChart(CityPopularity, options=list( slices="{4: {offset: 0.2}, 0: {offset: 0.3}}", title='City popularity', legend='none', pieSliceText='label', pieHole=0.5)) plot(Pie2)
A sankey diagram is a visualization used to depict a flow from one set of values to another. The things being connected are called nodes and the connections are called links. They're named after Captain Sankey, who created a diagram of steam engine efficiency that used arrows having widths proportional to heat loss.
gvisSankey(data, from = "", to = "", weight = "", options = list(), chartid)
gvisSankey(data, from = "", to = "", weight = "", options = list(), chartid)
data |
data.frame that contains the data to be visualised |
from |
a string that refers to the column name in
|
to |
a string that refers to the column name in
|
weight |
name of the column with the numerical weight of the connections |
options |
list of configuration options. The options are documented in detail by Google online: https://developers.google.com/chart/interactive/docs/gallery/sankey#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
gvisSankey returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
The sankey chart may be undergoing substantial revisions in future Google Charts releases.
Markus Gesmann [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/sankey
dat <- 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)) sk1 <- gvisSankey(dat, from="From", to="To", weight="Weight") plot(sk1) sk2 <- gvisSankey(dat, from="From", to="To", weight="Weight", options=list(sankey="{link: {color: { fill: '#d799ae' } }, node: { color: { fill: '#a61d4c' }, label: { color: '#871b47' } }}")) plot(sk2)
dat <- 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)) sk1 <- gvisSankey(dat, from="From", to="To", weight="Weight") plot(sk1) sk2 <- gvisSankey(dat, from="From", to="To", weight="Weight", options=list(sankey="{link: {color: { fill: '#d799ae' } }, node: { color: { fill: '#a61d4c' }, label: { color: '#871b47' } }}")) plot(sk2)
The gvisScatterChart function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page. The actual chart is rendered by the web browser using SVG or VML.
gvisScatterChart(data, options = list(), chartid)
gvisScatterChart(data, options = list(), chartid)
data |
a |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/scatterchart#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
gvisScatterChart returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/scatterchart
See also print.gvis
, plot.gvis
for
printing and plotting methods
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. ## Scatter chart Scatter1 <- gvisScatterChart(women) plot(Scatter1) ## Using optional arguments Scatter2 <- gvisScatterChart(women, options=list(legend="none", lineWidth=2, pointSize=2, title="Women", vAxis="{title:'weight (lbs)'}", crosshair="{ trigger: 'both' }", hAxis="{title:'height (in)'}", width=500, height=400)) plot(Scatter2) df=data.frame(x=sin(1:100/3), Circle=cos(1:100/3), Ellipse=cos(1:100/3)*0.5) ## Plot several variables as smooth curves Scatter3 <- gvisScatterChart(df, options=list(curveType='function', pointSize=0, lineWidth=2)) plot(Scatter3) ## Two series in the same plot with different ## x-values df <- data.frame(x=c(2,2,1,3,4), y1=c(0,3,NA,NA,NA), y2=c(NA,NA,0,3,2)) Scatter4 <- gvisScatterChart(df, options=list(lineWidth=2, pointSize=2)) plot(Scatter4) ## Customize points M <- matrix(nrow=6,ncol=6) M[col(M)==row(M)] <- 1:6 dat <- data.frame(X=1:6, M) SC <- gvisScatterChart(dat, options=list( title="Customizing points", legend="right", pointSize=30, series="{ 0: { pointShape: 'circle' }, 1: { pointShape: 'triangle' }, 2: { pointShape: 'square' }, 3: { pointShape: 'diamond' }, 4: { pointShape: 'star' }, 5: { pointShape: 'polygon' } }")) plot(SC)
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. ## Scatter chart Scatter1 <- gvisScatterChart(women) plot(Scatter1) ## Using optional arguments Scatter2 <- gvisScatterChart(women, options=list(legend="none", lineWidth=2, pointSize=2, title="Women", vAxis="{title:'weight (lbs)'}", crosshair="{ trigger: 'both' }", hAxis="{title:'height (in)'}", width=500, height=400)) plot(Scatter2) df=data.frame(x=sin(1:100/3), Circle=cos(1:100/3), Ellipse=cos(1:100/3)*0.5) ## Plot several variables as smooth curves Scatter3 <- gvisScatterChart(df, options=list(curveType='function', pointSize=0, lineWidth=2)) plot(Scatter3) ## Two series in the same plot with different ## x-values df <- data.frame(x=c(2,2,1,3,4), y1=c(0,3,NA,NA,NA), y2=c(NA,NA,0,3,2)) Scatter4 <- gvisScatterChart(df, options=list(lineWidth=2, pointSize=2)) plot(Scatter4) ## Customize points M <- matrix(nrow=6,ncol=6) M[col(M)==row(M)] <- 1:6 dat <- data.frame(X=1:6, M) SC <- gvisScatterChart(dat, options=list( title="Customizing points", legend="right", pointSize=30, series="{ 0: { pointShape: 'circle' }, 1: { pointShape: 'triangle' }, 2: { pointShape: 'square' }, 3: { pointShape: 'diamond' }, 4: { pointShape: 'star' }, 5: { pointShape: 'polygon' } }")) plot(SC)
The gvisSteppedAreaChart function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page.
gvisSteppedAreaChart(data, xvar = "", yvar = "", options = list(), chartid)
gvisSteppedAreaChart(data, xvar = "", yvar = "", options = list(), chartid)
data |
a |
xvar |
name of the character column which contains the category labels for the x-axes. |
yvar |
a vector of column names of the numerical variables to be plotted. Each column is displayed as a separate line. |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/steppedarechart#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
The stepped area chart is rendered within the browser using SVG or VML and displays tips when hovering over points.
gvisSteppedAreChart returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/steppedarechart
See also print.gvis
, plot.gvis
for
printing and plotting methods
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. df=data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32)) ## Stepped Area chart SteppedArea1 <- gvisSteppedAreaChart(df, xvar="country", yvar=c("val1", "val2")) plot(SteppedArea1) ## Stacked chart SteppedArea2 <- gvisSteppedAreaChart(df, xvar="country", yvar=c("val1", "val2"), options=list(isStacked=TRUE)) plot(SteppedArea2) ## Add a customised title SteppedArea3 <- gvisSteppedAreaChart(df, xvar="country", yvar=c("val1", "val2"), options=list(title="Hello World", titleTextStyle="{color:'red',fontName:'Courier',fontSize:16}")) plot(SteppedArea3) ## Not run: ## Change y-axis to percentages SteppedArea3 <- gvisSteppedAreaChart(df, xvar="country", yvar=c("val1", "val2"), options=list(vAxis="{format:'#,###%'}")) plot(SteppedArea3) ## End(Not run)
## Please note that by default the googleVis plot command ## will open a browser window and requires an internet ## connection to display the visualisation. df=data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32)) ## Stepped Area chart SteppedArea1 <- gvisSteppedAreaChart(df, xvar="country", yvar=c("val1", "val2")) plot(SteppedArea1) ## Stacked chart SteppedArea2 <- gvisSteppedAreaChart(df, xvar="country", yvar=c("val1", "val2"), options=list(isStacked=TRUE)) plot(SteppedArea2) ## Add a customised title SteppedArea3 <- gvisSteppedAreaChart(df, xvar="country", yvar=c("val1", "val2"), options=list(title="Hello World", titleTextStyle="{color:'red',fontName:'Courier',fontSize:16}")) plot(SteppedArea3) ## Not run: ## Change y-axis to percentages SteppedArea3 <- gvisSteppedAreaChart(df, xvar="country", yvar=c("val1", "val2"), options=list(vAxis="{format:'#,###%'}")) plot(SteppedArea3) ## End(Not run)
The gvisTable function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page. The actual chart is rendered by the web browser.
gvisTable(data, options = list(), chartid, formats = NULL)
gvisTable(data, options = list(), chartid, formats = NULL)
data |
a |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/table#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
formats |
named list. If |
A table that can be sorted and paged. Table cells can be formatted using format strings, or by directly inserting HTML as cell values. Numeric values are right-aligned; boolean values are displayed as check marks. Users can select single rows either with the keyboard or the mouse. Users can sort rows by clicking on column headers. The header row remains fixed as the user scrolls. The table fires a number of events corresponding to user interaction.
gvisTable returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/table
See also print.gvis
, plot.gvis
for
printing and plotting methods.
## Please note that by default the googleVis plot command ## will open a browser window and requires Flash and Internet ## connection to display the visualisation. ## Table with links to wikipedia (flags) tbl1 <- gvisTable(Population) plot(tbl1) ## Table with enabled paging tbl2 <- gvisTable(Population, options=list(page='enable', height='automatic', width='automatic')) plot(tbl2) ## Table with formating options tbl3 <- gvisTable(Population, formats=list(Population="#,###")) Population[['% of World Population']] <- Population[['% of World Population']]/100 tbl4 <- gvisTable(Population, formats=list(Population="#,###", '% of World Population'='#.#%')) plot(tbl4)
## Please note that by default the googleVis plot command ## will open a browser window and requires Flash and Internet ## connection to display the visualisation. ## Table with links to wikipedia (flags) tbl1 <- gvisTable(Population) plot(tbl1) ## Table with enabled paging tbl2 <- gvisTable(Population, options=list(page='enable', height='automatic', width='automatic')) plot(tbl2) ## Table with formating options tbl3 <- gvisTable(Population, formats=list(Population="#,###")) Population[['% of World Population']] <- Population[['% of World Population']]/100 tbl4 <- gvisTable(Population, formats=list(Population="#,###", '% of World Population'='#.#%')) plot(tbl4)
A timeline is a chart that depicts how a set of resources are used over time. One popular type of timeline is the Gantt chart.
gvisTimeline( data, rowlabel = "", barlabel = "", start = "", end = "", options = list(), chartid )
gvisTimeline( data, rowlabel = "", barlabel = "", start = "", end = "", options = list(), chartid )
data |
data.frame that contains the data to be visualised |
rowlabel |
a string that refers to the column name in
|
barlabel |
a string that refers to the column name in
|
start |
number, date or datetime for the start dates |
end |
number, date or datetime for the end dates |
options |
list of configuration options. The options are documented in detail by Google online: https://developers.google.com/chart/interactive/docs/gallery/timeline#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
gvisTimeline returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Markus Gesmann [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/timeline
dat <- data.frame(Term=c("1","2","3"), President=c("Whasington", "Adams", "Jefferson"), start=as.Date(x=c("1789-03-29", "1797-02-03", "1801-02-03")), end=as.Date(x=c("1797-02-03", "1801-02-03", "1809-02-03"))) tl <- gvisTimeline(data=dat[,-1], rowlabel="President", start="start", end="end") plot(tl) tl <- gvisTimeline(data=dat, barlabel="President", start="start", end="end") plot(tl) tl <- gvisTimeline(data=dat, rowlabel="President", start="start", end="end", options=list(timeline="{showRowLabels:false}")) plot(tl) dat <- data.frame(Position=c(rep("President", 3), rep("Vice", 3)), Name=c("Washington", "Adams", "Jefferson", "Adams", "Jefferson", "Burr"), start=as.Date(x=rep(c("1789-03-29", "1797-02-03", "1801-02-03"),2)), end=as.Date(x=rep(c("1797-02-03", "1801-02-03", "1809-02-03"),2))) tl <- gvisTimeline(data=dat, rowlabel="Name",barlabel="Position", start="start", end="end", options=list(timeline="{showRowLabels:true}")) plot(tl) tl <- gvisTimeline(data=dat, rowlabel="Name",barlabel="Position", start="start", end="end", options=list(timeline="{groupByRowLabel:false}", backgroundColor='#ffd', height=350, colors="['#cbb69d', '#603913', '#c69c6e']")) plot(tl) # Datetime example dat <- data.frame(Room=c("Room 1","Room 2","Room 3"), Language=c("English", "German", "French"), start=as.POSIXct(c("2014-03-14 14:00", "2014-03-14 15:00", "2014-03-14 14:30")), end=as.POSIXct(c("2014-03-14 15:00", "2014-03-14 16:00", "2014-03-14 15:30"))) tl <- gvisTimeline(data=dat, rowlabel="Language", start="start", end="end") plot(tl) ## Not run: require(timeline) data(ww2) timeline(ww2, ww2.events, event.spots=2, event.label='', event.above=FALSE) ww2$Person <- gsub("\\n" ," ", ww2$Person) plot(gvisTimeline(ww2, barlabel="Person", rowlabel="Group", start="StartDate", end="EndDate", options=list(width=600, height=350)) ) ## End(Not run)
dat <- data.frame(Term=c("1","2","3"), President=c("Whasington", "Adams", "Jefferson"), start=as.Date(x=c("1789-03-29", "1797-02-03", "1801-02-03")), end=as.Date(x=c("1797-02-03", "1801-02-03", "1809-02-03"))) tl <- gvisTimeline(data=dat[,-1], rowlabel="President", start="start", end="end") plot(tl) tl <- gvisTimeline(data=dat, barlabel="President", start="start", end="end") plot(tl) tl <- gvisTimeline(data=dat, rowlabel="President", start="start", end="end", options=list(timeline="{showRowLabels:false}")) plot(tl) dat <- data.frame(Position=c(rep("President", 3), rep("Vice", 3)), Name=c("Washington", "Adams", "Jefferson", "Adams", "Jefferson", "Burr"), start=as.Date(x=rep(c("1789-03-29", "1797-02-03", "1801-02-03"),2)), end=as.Date(x=rep(c("1797-02-03", "1801-02-03", "1809-02-03"),2))) tl <- gvisTimeline(data=dat, rowlabel="Name",barlabel="Position", start="start", end="end", options=list(timeline="{showRowLabels:true}")) plot(tl) tl <- gvisTimeline(data=dat, rowlabel="Name",barlabel="Position", start="start", end="end", options=list(timeline="{groupByRowLabel:false}", backgroundColor='#ffd', height=350, colors="['#cbb69d', '#603913', '#c69c6e']")) plot(tl) # Datetime example dat <- data.frame(Room=c("Room 1","Room 2","Room 3"), Language=c("English", "German", "French"), start=as.POSIXct(c("2014-03-14 14:00", "2014-03-14 15:00", "2014-03-14 14:30")), end=as.POSIXct(c("2014-03-14 15:00", "2014-03-14 16:00", "2014-03-14 15:30"))) tl <- gvisTimeline(data=dat, rowlabel="Language", start="start", end="end") plot(tl) ## Not run: require(timeline) data(ww2) timeline(ww2, ww2.events, event.spots=2, event.label='', event.above=FALSE) ww2$Person <- gsub("\\n" ," ", ww2$Person) plot(gvisTimeline(ww2, barlabel="Person", rowlabel="Group", start="StartDate", end="EndDate", options=list(width=600, height=350)) ) ## End(Not run)
The gvisTreeMap function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page. The actual chart is rendered by the web browser.
gvisTreeMap( data, idvar = "", parentvar = "", sizevar = "", colorvar = "", options = list(), chartid )
gvisTreeMap( data, idvar = "", parentvar = "", sizevar = "", colorvar = "", options = list(), chartid )
data |
a |
idvar |
column name of |
parentvar |
column name of |
sizevar |
column name of |
colorvar |
column name of |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/treemap#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
A tree map is a visual representation of a data tree, where each node can have zero or more children, and one parent (except for the root, which has no parents). Each node is displayed as a rectangle, sized and colored according to values that you assign. Sizes and colors are valued relative to all other nodes in the graph. You can specify how many levels to display simultaneously, and optionally to display deeper levels in a hinted fashion. If a node is a leaf node, you can specify a size and color; if it is not a leaf, it will be displayed as a bounding box for leaf nodes. The default behavior is to move down the tree when a user left-clicks a node, and to move back up the tree when a user right-clicks the graph.
The total size of the graph is determined by the size of the containing element that you insert in your page. If you have leaf nodes with names too long to show, the name will be truncated with an ellipsis (...).
gvisTreeMap returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
Tree maps display a tree like structure where every child has to have a unique parent.
Values in column sizevar
should be greater than zero and finite.
Markus Gesmann [email protected],
Diego de Castillo [email protected]
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/treemap
See also print.gvis
, plot.gvis
for printing and
plotting methods.
Please note that the treemap
package offeres a static version of tree
maps via its tmPlot
function.
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. Tree <- gvisTreeMap(Regions, idvar="Region", parentvar="Parent", sizevar="Val", colorvar="Fac") plot(Tree) Tree2 <- gvisTreeMap(Regions, "Region", "Parent", "Val", "Fac", options=list(width=600, height=500, fontSize=16, minColor='#EDF8FB', midColor='#66C2A4', maxColor='#006D2C', headerHeight=20, fontColor='black', showScale=TRUE)) plot(Tree2) ## Simple static treemap with no drill down options based on US states ## and their area. However we still have to create a parent id to use ## gvisTreeMap require(datasets) states <- data.frame(state.name, state.area) ## Create parent variable total=data.frame(state.area=sum(states$state.area), state.name="USA") my.states <- rbind(total, states) my.states$parent="USA" ## Set parent variable to NA at root level my.states$parent[my.states$state.name=="USA"] <- NA my.states$state.area.log=log(my.states$state.area) statesTree <- gvisTreeMap(my.states, "state.name", "parent", "state.area", "state.area.log") plot(statesTree) ## We add US regions to the above data set to enable drill down capabilities states2 <- data.frame(state.region, state.name, state.area) regions <- aggregate(list(region.area=states2$state.area), list(region=state.region), sum) my.states2 <- data.frame(regionid=c("USA", as.character(regions$region), as.character(states2$state.name)), parentid=c(NA, rep("USA", 4), as.character(states2$state.region)), state.area=c(sum(states2$state.area), regions$region.area, states2$state.area)) my.states2$state.area.log=log(my.states2$state.area) statesTree2 <- gvisTreeMap(my.states2, "regionid", "parentid", "state.area", "state.area.log") plot(statesTree2) ## Now we add another layer with US divisions states3 <- data.frame(state.region, state.division, state.name, state.area) regions <- aggregate(list(region.area=states3$state.area), list(region=state.region), sum) divisions <- aggregate(list(division.area=states3$state.area), list(division=state.division, region=state.region), sum) my.states3 <- data.frame(regionid=c("USA", as.character(regions$region), as.character(divisions$division), as.character(states3$state.name)), parentid=c(NA, rep("USA", 4), as.character(divisions$region), as.character(states3$state.division)), state.area=c(sum(states3$state.area), regions$region.area, divisions$division.area, states3$state.area)) my.states3$state.area.log=log(my.states3$state.area) statesTree3 <- gvisTreeMap(my.states3, "regionid", "parentid", "state.area", "state.area.log") plot(statesTree3)
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. Tree <- gvisTreeMap(Regions, idvar="Region", parentvar="Parent", sizevar="Val", colorvar="Fac") plot(Tree) Tree2 <- gvisTreeMap(Regions, "Region", "Parent", "Val", "Fac", options=list(width=600, height=500, fontSize=16, minColor='#EDF8FB', midColor='#66C2A4', maxColor='#006D2C', headerHeight=20, fontColor='black', showScale=TRUE)) plot(Tree2) ## Simple static treemap with no drill down options based on US states ## and their area. However we still have to create a parent id to use ## gvisTreeMap require(datasets) states <- data.frame(state.name, state.area) ## Create parent variable total=data.frame(state.area=sum(states$state.area), state.name="USA") my.states <- rbind(total, states) my.states$parent="USA" ## Set parent variable to NA at root level my.states$parent[my.states$state.name=="USA"] <- NA my.states$state.area.log=log(my.states$state.area) statesTree <- gvisTreeMap(my.states, "state.name", "parent", "state.area", "state.area.log") plot(statesTree) ## We add US regions to the above data set to enable drill down capabilities states2 <- data.frame(state.region, state.name, state.area) regions <- aggregate(list(region.area=states2$state.area), list(region=state.region), sum) my.states2 <- data.frame(regionid=c("USA", as.character(regions$region), as.character(states2$state.name)), parentid=c(NA, rep("USA", 4), as.character(states2$state.region)), state.area=c(sum(states2$state.area), regions$region.area, states2$state.area)) my.states2$state.area.log=log(my.states2$state.area) statesTree2 <- gvisTreeMap(my.states2, "regionid", "parentid", "state.area", "state.area.log") plot(statesTree2) ## Now we add another layer with US divisions states3 <- data.frame(state.region, state.division, state.name, state.area) regions <- aggregate(list(region.area=states3$state.area), list(region=state.region), sum) divisions <- aggregate(list(division.area=states3$state.area), list(division=state.division, region=state.region), sum) my.states3 <- data.frame(regionid=c("USA", as.character(regions$region), as.character(divisions$division), as.character(states3$state.name)), parentid=c(NA, rep("USA", 4), as.character(divisions$region), as.character(states3$state.division)), state.area=c(sum(states3$state.area), regions$region.area, divisions$division.area, states3$state.area)) my.states3$state.area.log=log(my.states3$state.area) statesTree3 <- gvisTreeMap(my.states3, "regionid", "parentid", "state.area", "state.area.log") plot(statesTree3)
A word tree depicts multiple parallel sequences of words. It could be used to show which words most often follow or precede a target word (e.g., "Cats are...") or to show a hierarchy of terms (e.g., a decision tree).
gvisWordTree( data, textvar = "", sizevar = "", stylevar = "", idvar = "", parentvar = "", options = list(), method = "implicit", chartid )
gvisWordTree( data, textvar = "", sizevar = "", stylevar = "", idvar = "", parentvar = "", options = list(), method = "implicit", chartid )
data |
|
textvar |
a string that refers to the column name in |
sizevar |
a string that refers to the column name in |
stylevar |
a string that refers to the column name in |
idvar |
(only when format is explicit) a string that refers to the
column name in |
parentvar |
(only when format is explicit) a string that refers to the
column name in |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/wordtree#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
method |
a string to say whether the word tree is either:
|
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
gvisWordTree returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
The word tree chart may be undergoing substantial revisions in future Google Charts releases.
Ashley Baldry
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/wordtree
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. wt1 <- gvisWordTree(Cats, textvar = "Phrase") plot(wt1) Cats2 <- Cats Cats2$Phrase.style <- ifelse(Cats$Sentiment >= 7, "green", ifelse(Cats$Sentiment <= 3, "red", "black")) wt2 <- gvisWordTree(Cats2, textvar = "Phrase", stylevar = "Phrase.style", options = list(fontName = "Times-Roman", wordtree = "{word: 'cats'}", backgroundColor = "#cba")) plot(wt2) # Explicit word tree exp.data <- data.frame(id = as.numeric(0:9), label = letters[1:10], parent = c(-1, 0, 0, 0, 2, 2, 4, 6, 1, 7), size = c(10, 5, 3, 2, 2, 2, 1, 1, 5, 1), stringsAsFactors = FALSE) wt3 <- gvisWordTree(exp.data, idvar = "id", textvar = "label", parentvar = "parent", sizevar = "size", options = list(wordtree = "{format: 'explicit'}"), method = "explicit") plot(wt3)
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. wt1 <- gvisWordTree(Cats, textvar = "Phrase") plot(wt1) Cats2 <- Cats Cats2$Phrase.style <- ifelse(Cats$Sentiment >= 7, "green", ifelse(Cats$Sentiment <= 3, "red", "black")) wt2 <- gvisWordTree(Cats2, textvar = "Phrase", stylevar = "Phrase.style", options = list(fontName = "Times-Roman", wordtree = "{word: 'cats'}", backgroundColor = "#cba")) plot(wt2) # Explicit word tree exp.data <- data.frame(id = as.numeric(0:9), label = letters[1:10], parent = c(-1, 0, 0, 0, 2, 2, 4, 6, 1, 7), size = c(10, 5, 3, 2, 2, 2, 1, 1, 5, 1), stringsAsFactors = FALSE) wt3 <- gvisWordTree(exp.data, idvar = "id", textvar = "label", parentvar = "parent", sizevar = "size", options = list(wordtree = "{format: 'explicit'}"), method = "explicit") plot(wt3)
Example data set to illustrate the use of the googleVis package.
data(OpenClose)
data(OpenClose)
A data frame with 5 observations on the following 5 variables.
Weekday
a factor with levels Fri
Mon
Thurs
Tues
Wed
Low
a numeric vector
Open
a numeric vector
Close
a numeric vector
High
a numeric vector
Google Visualisation: Candlestick Chart https://developers.google.com/chart/interactive/docs/gallery/candlestickchart?csw=1
OpenClose plot(gvisCandlestickChart(OpenClose, options=list(legend='none')))
OpenClose plot(gvisCandlestickChart(OpenClose, options=list(legend='none')))
Example data set to illustrate the use of the googleVis package.
data(Population)
data(Population)
A data frame with 195 observations on the following 7 variables.
Rank
a numeric vector with population ranking
Country
country name as character
Population
population
% of World Population
% of world population
Flag
html image-tag to wikipedia with country flag
Mode
logical test vector
Date
date test vector
Sourced from Wikipedia (columns 1 to 5): https://en.wikipedia.org/wiki/List_of_countries_by_population, 9 October 2010.
data(Population) tbl <- gvisTable(Population) ## Not run: plot(tbl) ## End(Not run)
data(Population) tbl <- gvisTable(Population) ## Not run: plot(tbl) ## End(Not run)
Example data set to illustrate the use of the googleVis package.
data(Regions)
data(Regions)
A data frame with 11 observations on the following 4 variables.
Region
a factor with levels America
, Asia
...
Parent
parent region identifier
Val
a numeric vector
Fac
a numeric vector
data(Regions) Tree <- gvisTreeMap(Regions, "Region", "Parent", "Val", "Fac", options=list(width=600, height=500, showScale=TRUE, fontSize=16)) ## Not run: plot(Tree) ## End(Not run)
data(Regions) Tree <- gvisTreeMap(Regions, "Region", "Parent", "Val", "Fac", options=list(width=600, height=500, showScale=TRUE, fontSize=16)) ## Not run: plot(Tree) ## End(Not run)
This function lets you use googleVis charts as Shiny output.
Use it to wrap a googleVis-generating function that you assign to an
output
element in server.R
; then create an htmlOutput
with the same name in ui.R
.
renderGvis(expr, env = parent.frame(), quoted = FALSE)
renderGvis(expr, env = parent.frame(), quoted = FALSE)
expr |
An expression that returns a gvis object. |
env |
The environment in which to evaluate |
quoted |
Is |
Use a googleVis Chart as Shiny Output
Returns a function that can be assigned to a Shiny output
element.
More information about shiny is available online: https://shiny.posit.co/. You find further examples with googleVis on shiny on mages' blog: https://magesblog.com/tags/shiny/
Joe Cheng, [email protected]
## Not run: # To run this example: shiny::runApp(system.file("shiny/", package="googleVis")) # server.R library(googleVis) shinyServer(function(input, output) { datasetInput <- reactive({ switch(input$dataset, "rock" = rock, "pressure" = pressure, "cars" = cars) }) output$view <- renderGvis({ gvisScatterChart(datasetInput(), options=list(title=paste('Data:',input$dataset))) }) }) # ui.R shinyUI(pageWithSidebar( headerPanel("googleVis on Shiny"), sidebarPanel( selectInput("dataset", "Choose a dataset:", choices = c("rock", "pressure", "cars")) ), mainPanel( htmlOutput("view") ) )) ## End(Not run)
## Not run: # To run this example: shiny::runApp(system.file("shiny/", package="googleVis")) # server.R library(googleVis) shinyServer(function(input, output) { datasetInput <- reactive({ switch(input$dataset, "rock" = rock, "pressure" = pressure, "cars" = cars) }) output$view <- renderGvis({ gvisScatterChart(datasetInput(), options=list(title=paste('Data:',input$dataset))) }) }) # ui.R shinyUI(pageWithSidebar( headerPanel("googleVis on Shiny"), sidebarPanel( selectInput("dataset", "Choose a dataset:", choices = c("rock", "pressure", "cars")) ), mainPanel( htmlOutput("view") ) )) ## End(Not run)
Example data set to illustrate the use of the googleVis package.
data(Stock)
data(Stock)
A data frame with 12 observations on the following 5 variables.
Date
a Date
Device
a character vector
Value
a numeric vector
Title
a factor with levels Bought pencils
Out of stock
Annotation
a factor with levels Bought 200k pencils
Ran of stock on pens at 4pm
Google Annotated Time Line API: https://developers.google.com/chart/interactive/docs/gallery/annotatedtimeline.html
## Create data as used by Google in their annotated time line example Date <- as.Date(paste("2008-1-", 1:6, sep="")) Pencils <- c(3000, 14045, 5502, 75284, 41476, 333222) Pencils.titles <-c(rep(NA,4), 'Bought pencils', NA) Pencils.annotation <-c(rep(NA,4), 'Bought 200k pencils', NA) Pens <- c(40645, 20374, 50766, 14334, 66467, 39463) Pens.titles <- c(rep(NA, 3), 'Out of stock', NA, NA) Pens.annotation <- c(rep(NA, 3), 'Ran of out stock of pens at 4pm', NA, NA) original.df=data.frame(Date, Pencils, Pencils.titles, Pencils.annotation, Pens, Pens.titles, Pens.annotation) Stock <- reshape(original.df, idvar="Date", times=c("Pencils", "Pens"), timevar="Device", varying=list(c("Pencils", "Pens"), c("Pencils.titles", "Pens.titles"), c("Pencils.annotation", "Pens.annotation")), v.names=c("Value", "Title", "Annotation"), direction="long")
## Create data as used by Google in their annotated time line example Date <- as.Date(paste("2008-1-", 1:6, sep="")) Pencils <- c(3000, 14045, 5502, 75284, 41476, 333222) Pencils.titles <-c(rep(NA,4), 'Bought pencils', NA) Pencils.annotation <-c(rep(NA,4), 'Bought 200k pencils', NA) Pens <- c(40645, 20374, 50766, 14334, 66467, 39463) Pens.titles <- c(rep(NA, 3), 'Out of stock', NA, NA) Pens.annotation <- c(rep(NA, 3), 'Ran of out stock of pens at 4pm', NA, NA) original.df=data.frame(Date, Pencils, Pencils.titles, Pencils.annotation, Pens, Pens.titles, Pens.annotation) Stock <- reshape(original.df, idvar="Date", times=c("Pencils", "Pens"), timevar="Device", varying=list(c("Pencils", "Pens"), c("Pencils.titles", "Pens.titles"), c("Pencils.annotation", "Pens.annotation")), v.names=c("Value", "Title", "Annotation"), direction="long")