era_cols <- c("before 1950" = "grey75", "1950-1989" = "grey45", "1990-2019" = "black")
pd <- era_size |>
left_join(distinct(summary_df, league, sport), by = "league") |>
mutate(group = sport_group(sport),
league = factor(league, levels = rev(recent$league)),
text = paste0(league, ", ", era, "<br>h = ", fmt(h), " (SE ", fmt(h_se), ")",
"<br>equal teams: home win ", pct(p_win),
if_else(p_draw > 0.005, paste0(", draw ", pct(p_draw)), ""),
", away win ", pct(p_loss),
"<br>expected score ", pct(share), " (SE ", fmt(100 * share_se, 1), " pts)",
"<br>", n_units, if_else(grepl("intern|Rugby", league), " decades, ", " seasons, "),
format(n_games, big.mark = ","), " games"))
# one row per league: the three eras sit on the same line, joined by a grey
# segment, with the most recent era darkest; the SEs are in the hover text
pd <- arrange(pd, league, era)
p <- ggplot(pd, aes(share, league, text = text)) +
geom_vline(xintercept = 0.5, colour = irw_grey) +
geom_path(aes(group = league), colour = "grey70", linewidth = 0.8) +
geom_point(aes(colour = era), size = 2.6) +
scale_colour_manual(values = era_cols) +
scale_x_continuous(labels = function(x) paste0(round(100 * x), "%")) +
labs(x = "home side's expected score, equal teams", y = NULL, colour = NULL)
lab_groups <- distinct(pd, league, group) |> arrange(league)
ggplotly(p, tooltip = "text") |>
layout(legend = list(orientation = "h", y = -0.15)) |>
colour_y_labels(as.character(lab_groups$league), lab_groups$group)