Created
August 29, 2025 14:01
-
-
Save andrewheiss/979fabf0ed21638b6d1692373b130947 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
library(tidyverse) | |
library(ggtext) | |
library(patchwork) | |
library(scales) | |
top_plot <- ggplot(penguins, aes(x = body_mass)) + | |
geom_histogram(binwidth = 100, color = "white", boundary = 0) + | |
scale_x_continuous( | |
breaks = seq(2500, 6500, by = 1000), | |
limits = c(2500, 6500), | |
labels = label_comma() | |
) + | |
labs(title = "All penguins", x = NULL, y = "Count") + | |
theme_bw() + | |
theme( | |
plot.title = element_textbox_simple( | |
face = "bold", | |
fill = "grey75", | |
size = rel(0.85), | |
halign = 0, | |
linetype = 1, | |
linewidth = 0.2, | |
padding = margin(5, 5, 5, 5) | |
), | |
strip.background = element_rect(fill = "grey92"), | |
strip.text = element_text(hjust = 0), | |
axis.title.y = element_text(hjust = 1) | |
) | |
bottom_plot <- penguins |> | |
ggplot(aes(x = body_mass, fill = species)) + | |
geom_histogram(binwidth = 100, color = "white", boundary = 0) + | |
scale_x_continuous( | |
breaks = seq(2500, 6500, by = 1000), | |
limits = c(2500, 6500), | |
labels = label_comma() | |
) + | |
guides(fill = "none") + | |
facet_wrap(vars(species), ncol = 1) + | |
labs(x = "Body mass (g)", y = "Count", title = "Specific penguin species") + | |
theme_bw() + | |
theme( | |
plot.title = element_textbox_simple( | |
face = "bold", | |
fill = "grey75", | |
size = rel(0.85), | |
halign = 0, | |
linetype = 1, | |
linewidth = 0.2, | |
padding = margin(5, 5, 5, 5) | |
), | |
strip.background = element_rect(fill = "grey92"), | |
strip.text = element_text(hjust = 0), | |
axis.title.x = element_text(hjust = 0), | |
axis.title.y = element_text(hjust = 1) | |
) | |
(top_plot / bottom_plot) + | |
plot_layout(heights = c(0.25, 0.75)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment