Sarah Cassie Burnett
September 16, 2025

Box Plot
geom_boxplot()
Violin Plot
geom_violin()
Density Plot
geom_density()
Bar Plot (Categorical)
geom_bar()
Heatmap
geom_tile()
Area Plot
geom_area()
Dot Plot
geom_dotplot()
Pie Chart
(usually a bar plot with coord_polar())
Ridgeline Plot
ggridges::geom_density_ridges()
Map Plot (Choropleth)
geom_polygon()
ggplot2 cheatsheetcolor = or scale_color_*) to modify the color of points, lines, or text.fill = or scale_fill_*) to modify the fill color of shapes like bars, boxes, or polygons.drama_films <- films |> filter(Genre == "Drama")
not_drama_films <- films |> filter(Genre != "Drama")
ggplot() +
geom_histogram(data = drama_films, aes(x = Length, fill = "Drama"),
alpha = 0.5, bins = 50) +
geom_histogram(data = not_drama_films, aes(x = Length, fill = "Not Drama"),
alpha = 0.5, bins = 50) +
labs(
x = "Length of the Movie",
y = "Number of Movies",
title = "Award Winning Movie Lengths by Genre",
caption = "Source: Telecom ParisTech",
fill = "Film Type"
) +
theme_minimal()drama_films <- films |> filter(Genre == "Drama")
not_drama_films <- films |> filter(Genre != "Drama")
ggplot() +
geom_histogram(data = drama_films, aes(x = Length, fill = "Drama"),
alpha = 0.5, bins = 50) +
geom_histogram(data = not_drama_films, aes(x = Length, fill = "Not Drama"),
alpha = 0.5, bins = 50) +
scale_fill_manual(values = c("Drama" = "red", "Not Drama" = "blue")) +
labs(
x = "Length of the Movie",
y = "Number of Movies",
title = "Award Winning Movie Lengths by Genre",
caption = "Source: Telecom ParisTech",
fill = "Film Type"
) +
theme_minimal()mutate to instead create a new column of data with this informationmutate to instead create a new column of data with this informationfilms2 <- films |>
mutate(GenreType = if_else(Genre == "Drama", "Drama", "Not Drama"))
ggplot(films2, aes(x = Length, fill = GenreType)) +
geom_histogram(bins = 50, alpha = 0.5) +
scale_fill_manual(values = c("Drama" = "red", "Not Drama" = "blue")) +
labs(
x = "Length of the Movie",
y = "Number of Movies",
title = "Award Winning Movie Lengths by Genre",
caption = "Source: Telecom ParisTech",
fill = "Film Type"
) +
theme_minimal()[1] 326
[1] 18823
[1] 57.73926
Over 50x difference
Note
Linear bins vs. Log bins
- Linear: equal dollars per bin (e.g., 0–300, 300–600, 600–900, …)
- Log10: equal factors per bin (e.g., 10^2 – 10^2.1, 10^2.1 – 10^2.2, …) or (about 100 – 126, …, 10000 – 12600)
library(patchwork)
d_linear <- ggplot(diamonds, aes(x = price, y = after_stat(density))) +
geom_histogram(bins = 100, fill = "hotpink4", color = "white") +
labs(
title = "Diamond Prices (Linear X)",
x = "Price",
y = "Density"
) +
theme_minimal()
d_log <- ggplot(diamonds, aes(x = price, y = after_stat(density))) +
geom_histogram(bins = 100, fill = "forestgreen", color = "white") +
scale_x_log10() +
labs(
title = "Diamond Prices (Log10 X)",
x = "Price (log scale)",
y = "Density"
) +
theme_minimal()
d_linear + d_logglimpse() and View()05:00