Created
December 17, 2017 21:38
-
-
Save thomasp85/361b4a83ffaa9985b0dd6b8e8e35a803 to your computer and use it in GitHub Desktop.
An R Notebook showing the difference in plotting ggplots and ggassemblies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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