简体   繁体   English

begin, end landscape 不旋转包含 ggplot 的页面 R markdown pdf

[英]begin , end landscape does not rotate pages containing ggplot in R markdown pdf

I m able to rotate my pages for my table outputs in pdf generated from r markdown.我可以为 r markdown 生成的 pdf 中的表输出旋转我的页面。
but when I want to rotate pages containing ggplot plots it does not work.但是当我想旋转包含 ggplot 图的页面时,它不起作用。 is there any other way for plots?还有其他方法吗?

---
output: pdf_document
header-includes:
  \usepackage{pdflscape}
  \usepackage{lscape}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```



\begin{landscape}

```{r pressure, echo=FALSE}
library(ggplot2)
ggplot(diamonds) + geom_point(aes(x=carat, y=price, color=cut)) + geom_smooth(aes(x=carat, y=price, color=cut)) 
```

\end{landscape}

It appears that knitr or Pandoc doesn't handle the Markdown figure inclusion within the landscape environment.看起来 knitr 或 Pandoc 没有处理 Markdown 图形包含在景观环境中。 However, this works for me:但是,这对我有用:

---
output: 
  pdf_document:
    keep_tex: true
header-includes:
  \usepackage{pdflscape}
  \usepackage{lscape}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

\begin{landscape}

This is the image:

```{r pressure, echo=FALSE, include=FALSE}
library(ggplot2)
ggplot(diamonds) + geom_point(aes(x=carat, y=price, color=cut)) + geom_smooth(aes(x=carat, y=price, color=cut)) 
```

\includegraphics{Untitled_files/figure-latex/pressure-1.pdf}

Yes, *that* was the image.
\end{landscape}

You'll need to change the name of the file to include depending on your own document, and it seems likely other Markdown markup will be ignored in that block, like the italic markers on *that* .您需要根据自己的文档更改要包含的文件的名称,并且似乎其他 Markdown 标记将在该块中被忽略,例如*that*上的斜体标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM