我有一个函数可以为不同的数据帧创建相同类型的googleVis
图。这些图将嵌入Markdown文件中。当我的函数创建图表对象时,使用result='asis'
选项嵌入单个图不能实现我的目标。以下是相同的虚拟代码:
Embedded googleVis plots
=====================
Some text here
```{r}
library(googleVis)
op <- options(gvis.plot.tag="chart")
```
And now the plot
```{r result='asis', tidy=TRUE}
mark_func <- function(data) {
data$Mean=mean(data$Popularity)
CC <- gvisComboChart(data, xvar='City',
yvar=c('Mean', 'Popularity'),
options=list(seriesType='bars',
width=450, height=300,
title='City Popularity',
series='{0: {type:"line"}}'))
return(CC)
}
```
```{r result='asis', tidy=TRUE}
plt <- mark_func(CityPopularity)
plot(plt)`
```
我正在使用knit2html
包中的knitr
将此Markdown文件转换为HTML,并在Firefox中查看此HTML。我没有看到情节,而是看到了很长的HTML代码。
我错过了什么?谢谢你的帮助。
答案 0 :(得分:4)
这只是错别字。您忘记在结尾处转义引号,代码块选项应为结果,而不是结果。
工作代码:
%\VignetteEngine{knitr::knitr}
```{r}
library(googleVis)
op <- options(gvis.plot.tag="chart")
```
```{r results='asis', tidy=TRUE}
mark_func <- function(d) {
d$Mean=mean(d$Popularity)
CC <- gvisComboChart(d, xvar='City',
yvar=c('Mean', 'Popularity'),
options=list(seriesType='bars',
width=450, height=300,
title='City Popularity',
series='{0: {type:\"line\"}}'))
return(CC)
}
```
```{r results='asis', tidy=TRUE}
plt <- mark_func(CityPopularity)
plot(plt)
```