Skip to content

Instantly share code, notes, and snippets.

@chrishanretty
Created March 8, 2025 12:19
Show Gist options
  • Save chrishanretty/ceb847b5c21a05a6638054600edc03fc to your computer and use it in GitHub Desktop.
Save chrishanretty/ceb847b5c21a05a6638054600edc03fc to your computer and use it in GitHub Desktop.
Women's empowerment in graphs
library(vdemdata)
library(tidyverse)
library(hrbrthemes)
library(ggtext)
data("vdem")
vdem <- vdem |>
filter(year > 1945)
### Plot trends in v2lgfemleg
p1 <- ggplot(vdem, aes(x = year,
y = v2lgfemleg)) +
geom_path(aes(group = country_text_id),
alpha = 1/8) +
scale_x_continuous("Year") +
scale_y_continuous("Proportion of lower chamber legislators who are women") +
geom_smooth(se = FALSE) +
labs(title = "Women's representation in parliaments has increased...",
subtitle = "Each line represents a country; blue line gives the average trend across countries",
caption = "Data: V-Dem Project, variable <span style = 'font-family: monospace'>v2lgfemleg</span>") +
theme_ipsum_rc() +
theme(plot.caption = element_markdown())
### Plot trends in v2pepwrgen
p2 <- ggplot(vdem, aes(x = year,
y = v2pepwrgen)) +
geom_path(aes(group = country_text_id),
alpha = 1/8) +
scale_x_continuous("Year") +
scale_y_continuous("Power distributed by gender\n(higher values indicate greater equality)") +
geom_smooth(se = FALSE) +
labs(title = "Even while women's share of power has plateaued...",
subtitle = "Each line represents a country; blue line gives the average trend across countries",
caption= "Data: V-Dem project, variable <span style = 'font-family: monospace'>v2pepwrgen</span>") +
theme_ipsum_rc() +
theme(plot.caption = element_markdown())
### Year on year correlations between the two
plot_df <- vdem |>
dplyr::select(year, country_text_id, v2pepwrgen, v2lgfemleg) |>
nest(data = c(country_text_id, v2pepwrgen, v2lgfemleg)) |>
mutate(the_cor = map_dbl(data, function(df)cor(df$v2pepwrgen, df$v2lgfemleg, use = "pairwise")),
the_cor_lo = map_dbl(data, function(df)cor.test(df$v2pepwrgen, df$v2lgfemleg, use = "pairwise")$conf.int[1]),
the_cor_hi = map_dbl(data, function(df)cor.test(df$v2pepwrgen, df$v2lgfemleg, use = "pairwise")$conf.int[2])
)
p3 <- ggplot(plot_df, aes(x = year, y = the_cor,
ymin = the_cor_lo,
ymax = the_cor_hi)) +
geom_pointrange(size = .5, colour = "darkgrey", alpha = 2/3) +
scale_x_continuous("Year") +
scale_y_continuous("Correlation between representation and equality of power",
limits = c(0, NA)) +
labs(title = "... because the association between legislative \nrepresentation and power varies over time") +
theme_ipsum_rc()
ggsave(p1,
file = "p1.png",
width = 7, height = 5,
bg = "white",
type = "Cairo")
ggsave(p2,
file = "p2.png",
width = 7, height = 5,
bg = "white",
type = "Cairo")
ggsave(p3,
file = "p3.png",
width = 7, height = 5,
bg = "white",
type = "Cairo")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment