```{r}
#| label: plot
### |- initial plot ----
p <- filtered_judo_medals |>
ggplot(aes(x = year, y = fct_reorder(country, medal_count, .fun = sum), fill = medal_count)) +
# Geoms
geom_tile(color = "white", linewidth = 0.15) +
geom_text(data = filtered_judo_medals |> filter(gender == "Men"),
aes(label = "Country", x = 1962, y = "Japan"),
size = 6.5, color = text_col, family = "text", fontface = "bold",
hjust = 1.4, vjust = -1.5) +
# Scales
scale_x_continuous(breaks = seq(
min(filtered_judo_medals$year),
max(filtered_judo_medals$year),
by = 4),
labels = function(x) paste0("'", substr(x, 3, 4))) +
scale_y_discrete() +
coord_cartesian(clip = "off") +
scale_fill_stepsn(
colors = c('#DFEDEB', "#A1FCDF", "#7FD8BE", "#FCD29F", "#FCAB64"),
limits = c(0, 7),
breaks = 0:7,
labels = as.character(0:7),
guide = guide_colorsteps(
direction = "horizontal",
barwidth = unit(10, "cm"),
barheight = unit(0.5, "cm"),
frame.colour = NA,
title.position = "top",
title.hjust = 1
)
) +
# Labs
labs(
title = title_text,
subtitle = subtitle_text,
caption = caption_text,
x = "Year",
y = "",
fill = "Medal Count"
) +
# Facet
facet_wrap(vars(gender), nrow = 2, axes = "all") +
# Theme
theme(
plot.title = element_markdown(
size = rel(1.5),
family = "title",
color = title_col,
face = "bold",
lineheight = 0.85,
margin = margin(t = 5, b = 10)
),
plot.subtitle = element_markdown(
size = rel(1.1),
family = "subtitle",
color = title_col,
lineheight = 1,
margin = margin(t = 5, b = 10)
),
plot.caption = element_markdown(
size = rel(.6),
family = "caption",
color = caption_col,
lineheight = 0.6,
hjust = 0,
halign = 0,
margin = margin(t = 10, b = 5)
),
)
### |- annotated plot ----
men_text <- str_glue("Judo made its first Olympic appearance in 1964,\nbut was not included on the program of\nthe 1968 Olympic Games.")
women_text <- str_glue("Women's judo made its first appearance at the\n1988 Olympic Games, as a demonstration sport.\nWomen's Judo became an official part of the\nOlympic games from the 1992 Barcelona games")
### |- final plot ----
p <- p +
# Men's Judo History Note
geom_text(data = filtered_judo_medals |> filter(gender == "Men"),
aes(x = 1964, y = Inf, label = men_text),
hjust = .6, vjust = -1.2,
size = 3.5, color = text_col, family = "anotation",
lineheight = 0.9) +
# Curved Arrow for Men's Note
geom_curve(data = filtered_judo_medals |> filter(gender == "Men"),
aes(x = 1968, y = "Japan", xend = 1968, yend = "South Korea"),
curvature = 0, arrow = arrow(type = "closed", length = unit(0.08, "inches")),
linewidth = .5,
color = text_col, size = 0.7) +
# Women's Judo History Note
geom_text(data = filtered_judo_medals %>% filter(gender == "Women"),
aes(label = women_text, x = 1962, y = "Japan"),
hjust = 0, vjust = 1, size = 3.5, color = text_col, family = "anotation",
lineheight = 0.9)
```