Learn R Programming

googleVis (version 0.2.4)

gvisMotionChart: Google Motion Chart with R

Description

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.

Usage

gvisMotionChart(data, idvar = "id", timevar = "time", 
		      date.format = "%Y/%m/%d", 
		      options = list(), chartid)

Arguments

data
a data.frame. The data has to have at least four columns with subject name (idvar), time (timevar) and two columns of numeric values. Further columns, numeric and character/factor are optional. The combin
idvar
column name of data with the subject to be analysed.
timevar
column name of data which shows the time dimension. The information has to be either numeric or of class Date.
date.format
if timevar is of class Date then this argument specifies how the dates are reformatted to be used by JavaScript.
options
list of configuration options for Google Motion Chart. The possible components are, taken from http://code.google.com/apis/visualization/documentation/gallery/motionchart.html#Configuration_Options: [object Object],[object Object],
chartid
character. If missing (default) a random chart id will be generated based on chart type and tempfile

Value

  • gvisMotionChart returns list of class "gvis" and "list". An object of class "gvis" is a list containing at least the following components:
  • typeGoogle visualisation type, here 'MotionChart'
  • chartidcharacter id of the chart object. Unique chart ids are required to place several charts on the same page.
  • htmla list with the building blocks for a page [object Object],[object Object],[object Object],[object Object]

References

Google Motion Chart API: http://code.google.com/apis/visualization/documentation/gallery/motionchart.html

Follow the link also for Google's Data Policy.

See Also

See also print.gvis, plot.gvis for printing and plotting methods, and also the animation-package and its function Rosling.bubbles.

Examples

Run this code
## Please note that by default the plot (better plot.gvis) command
## will open a browser window and requires Flash and Internet
## connection to display the visualisation.

Fruits	
## timevar Year
M1 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year")
str(M1)
## print.gvis, will concatenate the list into a one long string
M1

plot(M1)
## Usage of date variable
M2 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Date",
                               date.format = "/plot(M2)
## Options: no side panel on the right
M3 <- gvisMotionChart(Fruits,"Fruit","Year",
                 options=list(showSidePanel=FALSE))
plot(M3)
## Options: trails un-ticked
M4 <- gvisMotionChart(Fruits, "Fruit", "Year",
                 options=list(state='{\"showTrails\":false};'))

plot(M4)

Run the code above in your browser using DataLab