valueBox(paste0(round(nat$pct_early,1), "%"),
         "Share of votes cast before polling day (pre-poll + postal)")
17%
valueBox(paste0(round(nat$pct_pre_poll,1), "%"),
         "Pre-poll votes as % of total")
3.4%
valueBox(paste0(round(nat$pct_postal,1), "%"),
         "Postal votes as % of total")
13.6%
nat_long <- nat %>%
  select(pre_poll, postal, electionday) %>%
  pivot_longer(everything(), names_to="type", values_to="votes") %>%
  mutate(type = factor(type,
                       levels=c("electionday","pre_poll","postal"),
                       labels=c("Election day","Pre-poll","Postal")))
ggplot(nat_long, aes(type, votes / sum(votes), fill = type)) +
  geom_col(width = 0.7) +
  scale_y_continuous(labels = label_percent()) +
  scale_fill_brewer(palette = "Set2", guide = "none") +
  labs(title = "2025 vote-type composition (national)",
       x = NULL, y = NULL)

ggplot(div_master, aes(x = pct_early)) +
  geom_histogram(binwidth = 5, fill = "#8da0cb", colour = "white") +
  labs(title = "Distribution of early-vote share by division",
       x = "% of votes cast early (pre-poll + postal)", y = "Divisions")

div_master %>%
  arrange(desc(pct_early)) %>%
  slice_head(n = 40) %>%
  ggplot(aes(x = reorder(DivisionNm, pct_early), y = pct_early, fill = PartyAb)) +
  geom_col() +
  coord_flip() +
  labs(title = "Top 40 electorates by early voting",
       x = NULL, y = "% early (pre-poll + postal)") +
  theme(legend.position = "top")

top_bottom <- bind_rows(
  div_master %>% slice_max(pct_early, n = 10),
  div_master %>% slice_min(pct_early, n = 10)
) %>% select(DivisionNm, StateAb, pct_early, TurnoutPercentage, PartyAb)

reactable(top_bottom,
  columns = list(
    pct_early = colDef(name="% early", format = colFormat(digits=1)),
    TurnoutPercentage = colDef(name="Turnout %", format = colFormat(digits=1))
  ),
  compact = TRUE, bordered = TRUE)
ggplot(div_master, aes(x = pct_early, y = TurnoutPercentage, colour = PartyAb)) +
  geom_point(alpha = 0.7) +
  geom_smooth(se = FALSE, colour = "grey40") +
  labs(title = "Early-vote share vs turnout",
       x = "% early (pre-poll + postal)", y = "Turnout %") +
  theme(legend.position = "top")
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

if ("margin_2025" %in% names(div_master)) {
  ggplot(div_master, aes(x = pct_early, y = margin_2025, colour = PartyAb)) +
    geom_point(alpha = 0.7) +
    geom_smooth(se = FALSE, colour = "grey40") +
    labs(title = "Early-vote share vs electoral margin (TPP)",
         x = "% early (pre-poll + postal)", y = "Margin (percentage points)") +
    theme(legend.position = "top")
}
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'