从列表打印ggplots不工作在knitr与rmarkdown [英] Printing ggplots out of list does not work in knitr with rmarkdown

查看:309
本文介绍了从列表打印ggplots不工作在knitr与rmarkdown的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想把ggplots放入列表,然后在列表中打印每一个。这应该使用rmarkdown和knitr在RStudio。 MWE(当然,实际上,列表中填充别的地方比打印):

I would like to put ggplots into a list and then later print each one in the list. That should be done with rmarkdown and knitr in RStudio. MWE (of course, in real, the list gets filled somewhere else than printed):

---
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代码是

The LaTeX code I get is however

\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}{}!

当然结果不是很漂亮。

Of course the result is not pretty. What happended here?

推荐答案

这是最近在 knitr 1.12中引入的错误,它在开发版本(> = 1.12.2)中: https://github.com/yihui/knitr#安装

This is a bug recently introduced in knitr 1.12, and I have fixed it in the development version (>= 1.12.2): https://github.com/yihui/knitr#installation

这篇关于从列表打印ggplots不工作在knitr与rmarkdown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆