【发布时间】:2020-09-26 15:11:14
【问题描述】:
我在编写的 PDF R markdown 文档中遇到了空白页问题。看来,当我在单个代码块中绘制 2 个 ggplot() 图时,会在渲染图之前创建一个空白页。这是一个问题示例(完整的 .Rmd 文件,取消注释要运行的每个块的开头和结尾,UNCOMMENT 所在的位置!):
---
title: "Test"
author: "My Name"
output:
pdf_document:
number_sections: yes
toc: yes
---
\newpage
# Plots
## First subtitle
Here I plot some data:
#UNCOMMENT```{r pressure, echo=FALSE, message = FALSE}
library(tidyverse)
# line chart
ggplot(pressure, aes(x = temperature, y = pressure)) +
geom_line()
# step chart
ggplot(pressure, aes(x = temperature, y = pressure)) +
geom_step()
#UNCOMMENT```
\newpage
# More plots
#UNCOMMENT```{r, echo = FALSE}
# line chart with points
ggplot(pressure, aes(x = temperature, y = pressure)) +
geom_line() +
geom_point()
# line chart
ggplot(pressure, aes(x = temperature, y = pressure)) +
geom_line()
#UNCOMMENT```
编织时,PDF 输出在我的“更多绘图”块之前有一个空白页,即第 4 页是空白的:
知道为什么会发生这种情况以及如何解决这个问题吗?如果我将 2 个图分成 2 个不同的块,问题就解决了,但我想在一些块中绘制多个图,所以这不是一个解决方案。
提前致谢!
【问题讨论】:
标签: r ggplot2 r-markdown markdown knitr