I recently noticed that the same R markdown document was generating different plots when being run in different conditions (eg. different projects). As a toy example, consider the following document:
---
title: "Example"
output:
html_document
---
```{r plot, warning=FALSE, echo=FALSE}
library("tidyverse")
tibble(mu = c(-9.4, -9.3, -9.2, -9, -8.9, -8.8, -8.7, -8.5, -8.4, -8.3, 0),
N = c(1, 2, 1, 1, 1, 3, 1, 1, 1, 1, 3)) %>%
ggplot() +
geom_point(aes(x=mu, y=N)) +
geom_bar(aes(x=mu, y=N), stat="identity", fill="grey", colour="black", width=0.1) +
theme(panel.background=element_blank(),
axis.title=element_text(size=20),
axis.text=element_text(size=15))
```
It should produce a plot like the following one, and sometimes I am successful and get it:
However, other times, I get this alternate version, which is nonsense:
I have noticed that after loading the tidyverse package, some versions are different. For example, in the first one ggplot is 3.2.1, while in the later it is 3.3.0. This later has a different version number because it is maintained separately in a R project using Renv.
Ok, could it be the different version numbers? Even given these different versions as I known this package from long ago it is difficult to me to understand how the second plot could have been generated given this code in any ggplot version. Any hints on what could be causing this problem, if not the version numbers?