I want to make a series of histograms with the same data that facet wraps the histogram with different values for the number of bins. Using the palmerpenguins::penguin
dataset as an example:
library(palmerpenguins)
library(data.table)
library(ggplot2)
dt <- data.table(palmerpenguins::penguins)
ggplot(dt, aes(x = body_mass_g)) +
geom_histogram(bins = 3)
ggplot(dt, aes(x = body_mass_g)) +
geom_histogram(bins = 5)
which produce the expected plots:
What I want to do is facet wrap a series of these where the number of bins increments or is controlled by some variable. I think I’ve seen this done before with a single instance of ggplot() + geom_histogram() + facet_wrap()
where the facet_wrap()
has a parameter with some sequence, but I’m not sure if I’m misremembering.