Skip to content

Instantly share code, notes, and snippets.

@andrewheiss
Created May 9, 2025 16:00
Show Gist options
  • Save andrewheiss/6f87e72cf227db0f9d6f6d854807d678 to your computer and use it in GitHub Desktop.
Save andrewheiss/6f87e72cf227db0f9d6f6d854807d678 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(ggpattern)
publication_names <- c(
"Juvenile Instructor" = "J/I",
"Der Ster" = "NE",
"Der Wegweiser" = "GM",
"Juvenile Instructor + Der Ster" = "J/I;NE",
"Juvenile Instructor + Der Wegweiser" = "J/I;GM"
)
publication_data <- read_csv("~/Desktop/bloop.csv") |>
rename(year = ...1) |>
pivot_longer(!year, names_to = "month", values_to = "publication") |>
mutate(
publication = fct_recode(publication, !!!publication_names),
publication = fct_relevel(publication, names(publication_names))
)
plot_thing <- publication_data |>
mutate(month = fct_inorder(month)) |>
ggplot(aes(y = fct_rev(month), x = factor(year))) +
geom_tile_pattern(
aes(fill = publication, pattern_fill = publication),
pattern = "stripe",
pattern_density = 0.5, # Take up 50% of the pattern
pattern_spacing = 0.05, # Thinner stripes
pattern_size = 0, # No border on the stripes
pattern_key_scale_factor = 0.3 # Shrink the pattern in the legend
) +
geom_tile(color = "white", fill = NA, linewidth = 0.06) +
scale_fill_manual(
values = c("#0074D9", "#FF4136", "#FF851B", "#0074D9", "#0074D9"),
na.translate = FALSE
) +
scale_pattern_fill_manual(
values = c("#0074D9", "#FF4136", "#FF851B", "#FF4136", "#FF851B"),
na.translate = FALSE
) +
scale_color_manual(
values = c("white"),
na.translate = FALSE
) +
labs(
x = NULL,
y = NULL,
fill = NULL,
pattern_fill = NULL,
title = "Sacrament gems written by women in global LDS church magazines, 1920–1970"
) +
theme_minimal(base_family = "Lexend") +
theme(
panel.grid = element_blank(),
panel.background = element_rect(fill = "grey90", linewidth = 0),
legend.position = "top",
legend.justification = "left",
legend.margin = margin(l = 0, t = 2),
legend.key.width = unit(0.75, "lines"),
legend.key.height = unit(0.75, "lines"),
axis.text.x = element_text(angle = 270)
)
# For playing around with the dimensions
library(ggview)
plot_thing + canvas(width = 10, height = 3)
# Save stuff
ggsave(
"~/Desktop/example.png", plot_thing,
width = 10, height = 3, units = "in", res = 300,
bg = "white", device = ragg::agg_png
)
ggsave(
"~/Desktop/example.pdf", plot_thing,
width = 10, height = 3, units = "in",
device = cairo_pdf
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment