Skip to content

Instantly share code, notes, and snippets.

@thomasp85
Created December 17, 2017 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasp85/361b4a83ffaa9985b0dd6b8e8e35a803 to your computer and use it in GitHub Desktop.
Save thomasp85/361b4a83ffaa9985b0dd6b8e8e35a803 to your computer and use it in GitHub Desktop.
An R Notebook showing the difference in plotting ggplots and ggassemblies
---
title: "R Notebook"
output: html_notebook
---
# Difference in behavior between ggplot2 and patchwork plots in Notebooks
Consider the following ggplot
```{r}
library(ggplot2)
library(patchwork)
p <- ggplot(mtcars) + geom_point(aes(mpg, disp))
```
When plotting this we get, as expected, a single plot
```{r}
p
```
however, if we combine two ggplots with patchwork and displays it in a notebook
well get an additional empty plot
```{r}
p + p
```
looking at the source code for the two plotting functions it seems the grid
calls are identical...
```{r}
ggplot2:::print.ggplot
```
```{r}
patchwork:::print.ggassemble
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment