I would like to plot histograms of one variable x1, subdividing the data into 4 by values of another variable x2, and place the 4 histograms in 1 plot area, 2 histograms per row.
For example,
library(tidyverse)
ggplot(filter(mpg, cty < 15), aes(x = displ)) + geom_histogram(binwidth = 0.2)
ggplot(filter(mpg, cty == c(15,16,17,18)), aes(x = displ)) + geom_histogram(binwidth = 0.05)
ggplot(filter(mpg, cty == c(19,20,21,22)), aes(x = displ)) + geom_histogram(binwidth = 0.05)
ggplot(filter(mpg, cty > 23), aes(x = displ)) + geom_histogram(binwidth = 0.1)
Thanks for your help!