Created
October 28, 2012 15:30
-
-
Save mages/3968910 to your computer and use it in GitHub Desktop.
Markdown example with knitr and googleVis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
```{r setOptions, message=FALSE} | |
library(googleVis) | |
op <- options(gvis.plot.tag='chart') | |
``` | |
The following plot statements will automatically return the HTML | |
required for the 'knitted' output. | |
## Combo chart | |
```{r ComboExample, results='asis', tidy=FALSE} | |
## 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 | |
```{r gvisMergeExample, results='asis', echo=FALSE} | |
Geo <- gvisGeoChart(Exports, locationvar='Country', colorvar='Profit', | |
options=list(height=300, width=350)) | |
Tbl <- gvisTable(Exports, options=list(height=300, width=200)) | |
plot(gvisMerge(Geo, Tbl, horizontal=TRUE)) | |
`````` | |
Example of a gvisGeoChart with gvisTable and R code hidden. | |
## Motion Chart | |
```{r MotionChartExample, results='asis', tidy=FALSE} | |
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] | |
(http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html). | |
See the googleVis package vignette for more details. | |
```{r resetOptions} | |
## Set options back to original options | |
options(op) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment