Learn R Programming

googleVis (version 0.7.1)

gvisScatterChart: Google Scatter Chart with R googleChartName <- "scatterchart" gvisChartName <- "gvisScatterChart"

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)

Value

paste(gvisChartName) returns list of class

paste(readLines(file.path(".", "inst", "mansections", "gvisOutputStructure.txt")))

Arguments

data

a data.frame to be displayed as a scatter chart. Two or more columns are required, all must be numeric. The values in the first column are used for the X-axis. The values in following columns are used for the Y-axis. Each column is displayed with a separate color.

options

list of configuration options, see:

gsub("CHARTNAME", googleChartName, readLines(file.path(".", "inst", "mansections", "GoogleChartToolsURLConfigOptions.txt")))

paste(readLines(file.path(".", "inst", "mansections", "gvisOptions.txt")))

chartid

character. If missing (default) a random chart id will be generated based on chart type and tempfile

Author

Markus Gesmann markus.gesmann@gmail.com,

Diego de Castillo decastillo@gmail.com

References

Google Chart Tools API: gsub("CHARTNAME", googleChartName, readLines(file.path(".", "inst", "mansections", "GoogleChartToolsURL.txt")))

See Also

See also print.gvis, plot.gvis for printing and plotting methods

Examples

Run this code

## 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)

Run the code above in your browser using DataLab