从列表中打印 ggplots 在 knitr 和 rmarkdown 中不起作用
Printing ggplots out of list does not work in knitr with rmarkdown
我想将 ggplots 放入列表中,然后打印列表中的每一个。这应该通过 RStudio 中的 rmarkdown 和 knitr 来完成。 MWE(当然,实际上,列表是在打印的其他地方填充的):
---
title: "nice title"
author: "Me"
date: 12\. Januar 2016
output:
pdf_document:
fig_caption: yes
fig_width: 7
keep_tex: yes
number_sections: yes
toc: yes
html_document: default
---
Here is my plot:
```{r, echo=F}
library(ggplot2)
printGGlist <- function(gglist){
for(gg in gglist){
print(gg)
}
}
g1 <- ggplot(diamonds, aes(carat, cut)) + geom_point()
g2 <- ggplot(diamonds, aes(carat, cut)) + geom_density()
gg <- list(g1, g2)
printGGlist(gg)
```
more text
但是我得到的 LaTeX 代码是
\includegraphics{MyProject_files/figure-latex/unnamed-chunk-7-1.pdf}!
\href{MyProject_files/figure-latex/unnamed-chunk-7-2.pdf}{}!
\href{MyProject_files/figure-latex/unnamed-chunk-7-3.pdf}{}!
当然结果不尽如人意。这里发生了什么?
这是最近在knitr1.12引入的bug,我已经在开发版(>=1.12.2)修复了:https://github.com/yihui/knitr#installation
我想将 ggplots 放入列表中,然后打印列表中的每一个。这应该通过 RStudio 中的 rmarkdown 和 knitr 来完成。 MWE(当然,实际上,列表是在打印的其他地方填充的):
---
title: "nice title"
author: "Me"
date: 12\. Januar 2016
output:
pdf_document:
fig_caption: yes
fig_width: 7
keep_tex: yes
number_sections: yes
toc: yes
html_document: default
---
Here is my plot:
```{r, echo=F}
library(ggplot2)
printGGlist <- function(gglist){
for(gg in gglist){
print(gg)
}
}
g1 <- ggplot(diamonds, aes(carat, cut)) + geom_point()
g2 <- ggplot(diamonds, aes(carat, cut)) + geom_density()
gg <- list(g1, g2)
printGGlist(gg)
```
more text
但是我得到的 LaTeX 代码是
\includegraphics{MyProject_files/figure-latex/unnamed-chunk-7-1.pdf}!
\href{MyProject_files/figure-latex/unnamed-chunk-7-2.pdf}{}!
\href{MyProject_files/figure-latex/unnamed-chunk-7-3.pdf}{}!
当然结果不尽如人意。这里发生了什么?
这是最近在knitr1.12引入的bug,我已经在开发版(>=1.12.2)修复了:https://github.com/yihui/knitr#installation