Last active
April 23, 2019 11:15
-
-
Save matt-dray/e063b6d590b1cc6cb9c17cdd79c15d7d to your computer and use it in GitHub Desktop.
Display a {googleVis} graphic in R Markdown
This file contains 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
--- | |
title: "googleVis test" | |
author: "Matt Dray" | |
date: "23/04/2019" | |
output: html_document | |
--- | |
Set up example dataframe from [the {googleVis} examples](https://cran.r-project.org/web/packages/googleVis/vignettes/googleVis_examples.html) CRAN vignette. | |
```{r} | |
df <- data.frame( | |
country = c("US", "GB", "BR"), | |
val1 = c(10, 13, 14), | |
val2 = c(23, 12, 32) | |
) | |
``` | |
Call library and set options as in the [Markdown example with knitr and googleVis](https://cran.r-project.org/web/packages/googleVis/vignettes/Using_googleVis_with_knitr.html) CRAN vignette. | |
```{r} | |
library(googleVis) | |
op <- options(gvis.plot.tag = 'chart') | |
``` | |
Create and plot. Make sure you set `results='asis'` in the chunk settings so the JavaScript for your plot is read and compiled as an image. | |
```{r results='asis'} | |
Line <- gvisLineChart(df, options = list(title = "Var by country")) | |
plot(Line) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment