You may have a series of plots you want to share as part of your analysis (e.g. plots in exploratory data analysis, plots to check model conditions), but you don’t want the reader to need to scroll through pages of plots. The patchwork package in R makes it easy to combine multiple plots and neatly organize them in a grid.
# if you need to install the package
#install.packages("patchwork")
library(tidyverse)
library(patchwork)
mtcars <- mtcars %>%
mutate(am = factor(am))
p1 <- ggplot(data = mtcars, aes(x = mpg)) +
geom_histogram(fill = "steelblue") +
labs(x = "Miles per gallon",
title = "Distribution of car mileage")
p2 <- ggplot(data = mtcars, aes(x = am)) +
geom_bar(fill = "steelblue") +
labs(x = "Transmission type",
title = "Car transmissions",
subtitle = "0: automatic, 1: manual")
p3 <- ggplot(data = mtcars, aes(x = am, y = mpg)) +
geom_boxplot(fill = "steelblue") +
labs(x = "Transmission type",
y = "Miles per gallon",
title = "Mileage vs. Transmission")
p1 + p2
p1 / p2
p3 + (p1 / p2)
Clone the ae-06 repo and open a new project in RStudio. Be sure to push your work periodically as you complete the AE.