I struggle with a blank page problem in my knited PDF R markdown document. It appears that when I plot 2 ggplot() graphs in a single code chunk, a blank page is created before rendering the graphs. Here is an example of the problem (complete .Rmd file, uncomment beginning and ending of each chunk to run, where UNCOMMENT stands!):
---
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```
When knited, the PDF output has a blank page before my "More plots" chunk, i.e. 4th page is blank:
Any idea why it happens and how to solve that issue? If I separate the 2 plots in 2 different chunks the problem is solved but I want to plot multiple graphs in some chunks so it's not a solution.
Thanks in advance!