我想将ggplots放入列表中,然后在列表中打印每个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}{}!
当然结果并不漂亮。这里发生了什么?
答案 0 :(得分:3)
这是最近在 knitr 1.12中引入的错误,我在开发版本中修复了它(&gt; = 1.12.2):https://github.com/yihui/knitr#installation