## S3 method for class 'gvis'print(x, tag=NULL, file ="",...)## S3 method for class 'gvis'plot(x, tag=NULL,...)
Arguments
x: An object of class gvis, or a HTML file in case of plot.gvis.
tag: Default NULL. Name tag of the objects to be extracted from a gvis object. If tag is missing then the values of getOption("gvis.print.tag"), getOption("gvis.plot.tag") will be used for print.gvis
and plot.gvis respectively.
A complete list of available tags is given by the command getOption("gvis.tags").
The default value of gvis.print.tag is "html", which means print.gvis will show a complete web page with the visualisation, while the tag "chart" will present the code for the visualisation chart only. For more information see the details section.
The default tag for plot.gvis.tag is NULL, which will result in R opening a browser window, while any tag which is not NULL will give the same behaviour as print.gvis, e.g. tag='chart' or setting options(gvis.plot.tag='chart')
will produce the same output as print(x, tag='chart'). This behaviour is particular helpful when googleVis is used in scripts, like knitr or R.rsp. The plot commands can be used initially in an interactive mode and with one change in options() produce the HTML output required for a programmatic run of the script. See the example section below for a knitr case study.
plot.gvis ignores the argument tag it x is a HTML file name.
file: file name. If "" (the default), output will be printed to the standard output connection, the console unless redirected by sink.
...: arguments passed on to cat
(print.gvis) or browseURL (plot.gvis).
Details
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.
Returns
print.gvis: None (invisible NULL).
plot.gvis: Returns the file name invisibly.
References
Please see also the package vignette for the usage of the googleVis package with RApache, brew, knitr and R.rsp.
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.
See Also
See also cat, browseURL, createGoogleGadget and gvisMerge for combining charts.
Examples
## Show gvis optionssapply(c("gvis.print.tag","gvis.plot.tag","gvis.tags"), getOption)M <- gvisMotionChart(Fruits,"Fruit","Year")str(M)## The output for a complete web pageM
## 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 googleVisknitrRmd <-"
# 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.