Within R I use the ggplot2 plotting library to create plots. I output a bunch of them and also print \n\n
in between them such that they become their own paragraph in the PDF (via LaTeX). Lately (new R version, I think) the plots started to get cropped in this way:
The title and the legend are not completely visible, and I do not get why this happens. I am using R 3.6.1 with ggplot2 3.2.1 on Fedora 31. Is there some way to make them readable again?
And this is the whole code:
---
title: "Cropping MWE"
author: "Martin Ueding"
date: \today
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
```
We can try it with ggplot2:
```{r}
ggplot(diamonds, aes(x = x, y = y, color = color)) +
geom_point() +
labs(title = 'Shape and color of diamonds')
```
And then we can also try it using the built-in plotting.
```{r}
with(diamonds, plot(x, y, main = 'Shape and color of diamonds'))
```
And some more text afterwards.
I can change the header to prevent cropping at all, and then it does work.
---
title: "Cropping MWE"
author: "Martin Ueding"
date: \today
output:
pdf_document:
fig_crop: false
---
Then however the figures have a bit of stray space around them, which is not perfect either.