Skip to content

Instantly share code, notes, and snippets.

@chrishanretty
Created June 12, 2024 12:41
Show Gist options
  • Save chrishanretty/1e5ecbf9049c87e893f314969bf034f5 to your computer and use it in GitHub Desktop.
Save chrishanretty/1e5ecbf9049c87e893f314969bf034f5 to your computer and use it in GitHub Desktop.
Cost of governing for populist parties
library(here)
library(tidyverse)
library(colorspace)
library(RColorBrewer)
library(hrbrthemes)
set.seed(2686)
here::i_am("R/rr_cog.R")
elex <- read.csv(here::here("data", "view_election.csv"))
### Create year to use later
elex <- elex |>
mutate(election_date = as.Date(election_date),
year = as.numeric(format(election_date, "%Y")))
### Just entries from the post-1945 period
elex <- elex |>
filter(year >= 1945) |>
filter(election_type == "parliament")
### Calculate change in vote share by a self-join, using the previous
### election ID as key.
elex <- left_join(elex,
elex |> distinct(election_id, party_id, vote_share),
by = join_by(previous_parliament_election_id == election_id,
party_id == party_id),
suffix = c("", ".lagged"))
### Remove cases where that party doesn't have a previous vote share
elex <- elex |>
mutate(delta = vote_share - vote_share.lagged) |>
ungroup() |>
filter(!is.na(delta))
### Remove the 1981 Cyprus election, where a party is recorded as
### having lost a lot because an alliance splintered
elex <- elex |>
filter(election_id != 70)
### Get cabinet
### status
cabs <- read.csv(here::here("data", "view_cabinet.csv")) |>
dplyr::select(cabinet_id, party_id, cabinet_party)
elex <- left_join(elex,
cabs,
by = join_by(previous_cabinet_id == cabinet_id,
party_id == party_id))
### Remove instances where we don't know whether they were a cabinet party
elex <- elex |>
filter(!is.na(cabinet_party))
## Filter to countries in the popuLust
populist_countries <- c("AUT", "BEL", "BGR", "HRV", "CYP",
"CZE", "DNK", "EST", "FIN", "FRA",
"DEU", "GRC", "HUN", "ISL", "IRL",
"ITA", "LVA", "LTU", "LUX", "NLD",
"NOR", "POL", "PRT", "ROU", "SVK",
"SVN", "ESP", "SWE", "CHE", "GBR")
elex <- elex |>
filter(country_name_short %in% populist_countries)
### Add on the populist
populist <- read.delim(here::here("data",
"The PopuList 3.0.csv"),
sep = ";")
populist <- populist |>
dplyr::select(parlgov_id, populist,
populist_start,
populist_end)
### Join
elex <- left_join(elex, populist,
by = join_by(party_id == parlgov_id,
year >= populist_start,
year <= populist_end))
### If they're not in the populist, they're not populist
elex <- elex |>
mutate(populist = coalesce(populist, 0L))
elex <- elex |>
mutate(type = case_when(populist == 1 & cabinet_party == 1 ~ "Populist party IN government",
populist == 1 & cabinet_party == 0 ~ "Populist party OUT OF government",
populist == 0 & cabinet_party == 1 ~ "Non-populist party IN government",
populist == 0 & cabinet_party == 0 ~ "Non-populist party OUT OF government",
TRUE ~ "Missing data"),
type = factor(type,
levels = c("Populist party IN government",
"Non-populist party IN government",
"Populist party OUT OF government",
"Non-populist party OUT OF government"),
ordered = TRUE))
my_pal <- brewer.pal(4, "Paired")
### Rearrange
my_pal <- my_pal[c(2, 4, 1, 3)]
my_comparisons <- list( c("Populist party IN government",
"Non-populist party IN government"))
p <- ggplot(elex, aes(x = type, y = delta, colour = type, fill = type)) +
scale_x_discrete("") +
scale_y_continuous("Change in vote share between consecutive elections in percentage points",
limits = c(-50, NA)) +
geom_hline(yintercept = 0) +
geom_boxplot(width = 0.5) +
scale_fill_manual(values = my_pal,
guide = "none") +
scale_colour_manual(values = darken(my_pal, 0.3),
guide = "none") +
coord_flip() +
stat_compare_means(comparisons = my_comparisons, label = "p.signif") +
labs(title = "Populist parties lose votes when in government like all other parties",
subtitle = "No significant differences in governing party losses comparing populist to non-populist parties",
caption = "Data: ParlGov / PopuList v3.0") +
theme_ipsum_rc() +
theme(plot.title.position = "plot")
ggsave(p, file = "populist_losses.png", width = 9, height = 6, dpi = 96, bg = "white")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment