Skip to content

Instantly share code, notes, and snippets.

@stephenturner
Created February 3, 2026 21:09
Show Gist options
  • Select an option

  • Save stephenturner/f68cba765ce26ca2baaefc9872579517 to your computer and use it in GitHub Desktop.

Select an option

Save stephenturner/f68cba765ce26ca2baaefc9872579517 to your computer and use it in GitHub Desktop.
Code accompanying blog post at https://blog.stephenturner.us/p/plot-titles
# https://blog.stephenturner.us/p/plot-titles
library(dplyr)
library(ggplot2)
ggplot(diamonds, aes(x = carat)) +
geom_histogram(binwidth = 0.1) +
labs(
title = "Most diamonds are under 1 carat; larger stones are rare",
subtitle = "Histogram of ~54k diamonds in ggplot2::diamonds (binwidth = 0.1)",
x = "Carat",
y = "Count"
) +
theme_minimal()
ggplot(diamonds, aes(x = carat, y = price)) +
geom_point(alpha = 0.08) +
scale_y_continuous(labels = scales::dollar) +
labs(
title = "Carat strongly predicts price, but the spread is huge at any given size",
subtitle = "Same carat, very different prices: quality and other attributes dominate within-size variation",
x = "Carat",
y = "Price (USD)"
) +
theme_minimal()
ggplot(penguins, aes(x = flipper_len, y = bill_len, color = species)) +
geom_point(alpha = 0.8, na.rm = TRUE) +
labs(
title = "Species are mostly separable with two simple measurements",
subtitle = "Adelie, Chinstrap, and Gentoo form distinct clusters (some overlap remains)",
x = "Flipper length (mm)",
y = "Bill length (mm)",
color = "Species"
) +
theme_minimal()
dplyr::starwars |>
filter(!is.na(height), !is.na(mass), mass < 500) |>
ggplot(aes(x = height, y = mass)) +
geom_point(alpha = 0.7) +
geom_smooth(se = FALSE) +
labs(
title = "Taller characters tend to be heavier, but the outliers are the story",
subtitle = "Filtered to mass < 500 for readability; trend line summarizes the overall pattern",
x = "Height (cm)",
y = "Mass (kg)"
) +
theme_minimal()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment