Skip to content

Instantly share code, notes, and snippets.

@chrishanretty
Last active March 17, 2026 09:29
Show Gist options
  • Select an option

  • Save chrishanretty/e3120f1306e244d63d392931455bf0cc to your computer and use it in GitHub Desktop.

Select an option

Save chrishanretty/e3120f1306e244d63d392931455bf0cc to your computer and use it in GitHub Desktop.
Analysis of V-Dem scores for UK in 2026 release
library(tidyverse)
library(cowplot)
dat <- readRDS("V-Dem-CY-Core-v16.rds")
gbr <- dat |>
filter(country_text_id == "GBR")
### What's the overall picture?
p <- ggplot(gbr |> filter(year > 1945),
aes(x = year, y = v2x_libdem,
ymin = v2x_libdem_codelow,
ymax = v2x_libdem_codehigh)) +
geom_ribbon(colour = "lightgrey", alpha = 0.5) +
geom_path() +
theme_bw()
### What's the picture for polyarchy alone?
p2 <- ggplot(gbr |> filter(year > 1945),
aes(x = year, y = v2x_polyarchy,
ymin = v2x_polyarchy_codelow,
ymax = v2x_polyarchy_codehigh)) +
geom_ribbon(colour = "lightgrey", alpha = 0.5) +
geom_path() +
theme_bw()
### Okay, the decline is present in the polyarchy measure, so let's drill down
components <- c("v2x_freexp_altinf",
"v2x_frassoc_thick",
"v2xel_frefair")
components <- c(components,
paste0(components, "_codelow"),
paste0(components, "_codehigh"))
### Remove those which don't exist
components <- components[components %in% names(gbr)]
gbr_long <- gbr |>
dplyr::select(year, all_of(components)) |>
pivot_longer(cols = all_of(components)) |>
mutate(measure = sub("_code.*", "", name),
level = case_when(grepl("codelow", name) ~ "lo",
grepl("codehigh", name) ~ "hi",
TRUE ~ "main")) |>
pivot_wider(id_cols = c(year, measure),
names_from = level,
values_from = value) |>
mutate(measure = dplyr::recode(measure,
"v2x_freexp_altinf" = "Freedom of expression / alt. info",
"v2x_frassoc_thick" = "Freedom of association",
"v2xel_frefair" = "Free and fair elections"))
p3 <- ggplot(gbr_long |> filter(year > 1945),
aes(x = year, y = main, ymin = lo, ymax = hi,
group = measure,
fill = measure,
colour = measure)) +
scale_x_continuous("Year") +
scale_y_continuous("Level (0-1; higher values are better)") +
geom_ribbon(alpha = 1/3) +
geom_path() +
facet_wrap(~measure) +
theme_bw()
### Okay, what's changing in freedom of expression?
frexp <- c("v2mecenefm",
"v2meharjrn",
"v2meslfcen",
"v2mebias",
"v2merange",
"v2mecrit",
"v2cldiscm",
"v2cldiscw",
"v2clacfree")
components <- c(frexp,
paste0(frexp, "_codelow"),
paste0(frexp, "_codehigh"))
### Remove those which don't exist
components <- components[components %in% names(gbr)]
gbr_long <- gbr |>
dplyr::select(year, all_of(components)) |>
pivot_longer(cols = all_of(components)) |>
mutate(measure = sub("_code.*", "", name),
level = case_when(grepl("codelow", name) ~ "lo",
grepl("codehigh", name) ~ "hi",
TRUE ~ "main")) |>
pivot_wider(id_cols = c(year, measure),
names_from = level,
values_from = value) |>
mutate(measure = dplyr::recode(measure,
"v2mecenefm" = "Government censorship",
"v2meharjrn" = "Harassment of journalists",
"v2meslfcen" = "Self-censorship",
"v2mebias" = "Bias",
"v2merange" = "Range of perspectives",
"v2mecrit" = "Media critical",
"v2cldiscm" = "Freedom of discussion for men",
"v2cldiscw" = "Freedom of discussion for women",
"v2clacfree" = "Academic and cultural expression"))
p4 <- ggplot(gbr_long |> filter(year > 1945),
aes(x = year, y = main, ymin = lo, ymax = hi,
group = measure,
fill = measure,
colour = measure)) +
scale_x_continuous("Year") +
scale_y_continuous("Level") +
geom_ribbon(alpha = 1/3) +
geom_path() +
facet_wrap(~measure) +
theme_bw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment