## Markdown example with knitr and googleVis

This is a little Markdown example output. The Markdown source file is hosted on GitHub.

Set the googleVis options first to change the behaviour of plot.gvis, so that only the chart component of the HTML file is written into the output file.

library(googleVis)
op <- options(gvis.plot.tag='chart')

The following plot statements will automatically return the HTML required for the ‘knitted’ output.

Combo chart

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

Example of a gvisGeoChart with gvisTable and R code hidden.

Motion Chart

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 if placed in a directory which has been added to the trusted sources in the [security settings of Macromedia] (http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html). See the googleVis package vignette for more details.

## Set options back to original options
options(op)