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

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 is placed in a directory which has been added to the trusted sources in the security settings of Macromedia. See the googleVis package vignette for more details.

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