gvisScatterChart {googleVis} | R Documentation |
Google Scatter Chart with R
Description
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.
Usage
gvisScatterChart(data, options = list(), chartid)
Arguments
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 |
Value
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.
Author(s)
Markus Gesmann markus.gesmann@gmail.com,
Diego de Castillo decastillo@gmail.com
References
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/scatterchart
See Also
See also print.gvis
, plot.gvis
for
printing and plotting methods
Examples
## 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)