Skip to content

Instantly share code, notes, and snippets.

@chrishanretty
Created September 12, 2022 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrishanretty/27304c6d9c3c44bb009a25f2eb723107 to your computer and use it in GitHub Desktop.
Save chrishanretty/27304c6d9c3c44bb009a25f2eb723107 to your computer and use it in GitHub Desktop.
How often is the Prime Minister supplied by the third (or fourth-, or fifth-) ranked party?
library(tidyverse)
library(hrbrthemes)
library(ggtext)
dat <- read.csv("view_cabinet.csv")
dat <- dat %>%
group_by(country_name_short,
country_id,
election_date,
start_date,
cabinet_name,
cabinet_id) %>%
arrange(desc(seats)) %>%
mutate(seat_rank = 1:n()) %>%
ungroup() %>%
filter(prime_minister == 1)
plot.df <- dat %>%
filter(seats > 0) %>%
count(seat_rank) %>%
mutate(proportion = n / sum(n),
fill = ifelse(seat_rank > 2, "yup", "nope"))
p <- ggplot(plot.df, aes(x = seat_rank, y = proportion,
fill = fill)) +
scale_x_continuous("Seat rank of Prime Minister's party") +
scale_y_continuous("Proportion of total cabinets",
labels = scales::percent) +
scale_fill_manual(values = c("#999999", "#990000"), guide = NULL) +
labs(title = "How often does the third- (or fourth-) placed party supply the PM?",
subtitle = paste0("Around <span style = 'color: #990000; font-weight: bold'>",
round(100 * sum(plot.df$proportion[-c(1:2)])),
"% of the time</span>"),
caption = "Data: @ParlGov. Excludes cabinets where the PM's party was not represented in the legislature") +
geom_col() +
theme_ipsum_rc() +
theme(plot.subtitle = element_markdown())
ggsave(p, file = "pm_party_rank.png", width = 9, height = 7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment