Skip to content

Instantly share code, notes, and snippets.

@z3tt
Created December 29, 2022 18:51
Show Gist options
  • Save z3tt/c58761aacc78ba52d6a305ccca3cce56 to your computer and use it in GitHub Desktop.
Save z3tt/c58761aacc78ba52d6a305ccca3cce56 to your computer and use it in GitHub Desktop.
Human Rights Protection Scores of USA and Germany
## packages
library(ggplot2)
library(dplyr)
library(tidyr)
library(ggbraid)
library(colorspace)
library(owidR)
# plus ggtext via namespace
## data
rights <- owid("human-rights-protection")
rights_long <-
rights %>%
filter(code %in% c("USA", "DEU")) %>%
select(code, year, "rights" = `Human rights protection`)
rights_wide <- pivot_wider(rights_long, names_from = code, values_from = rights)
## fonts
systemfonts::register_variant(
name = "Cabinet Grotesk S1 Regular",
family = "Cabinet Grotesk",
weight = "normal",
features = systemfonts::font_feature(letters = "stylistic")
)
systemfonts::register_variant(
name = "Cabinet Grotesk S1 ExtraBold",
family = "Cabinet Grotesk",
weight = "ultrabold",
features = systemfonts::font_feature(letters = "stylistic")
)
## theme
theme_set(theme_minimal(base_size = 14, base_family = "Cabinet Grotesk S1 Regular"))
theme_update(
plot.title = ggtext::element_textbox_simple(
family = "Cabinet Grotesk S1 ExtraBold", size = 27,
lineheight = .98, margin = margin(8, 0, 12, 0)
),
plot.subtitle = ggtext::element_textbox_simple(
size = 16.5, lineheight = 1.05, margin = margin(0, 0, 18, 0)
),
plot.caption = element_text(
size = 12, color = "grey40", hjust = 0, margin = margin(18, 0, 0, 0)
),
plot.title.position = "plot",
plot.caption.position = "plot",
axis.text.x = element_text(
family = "Tabular", size = 13, color = "grey28"
),
axis.text.y = element_text(
family = "Cabinet Grotesk S1 Regular", size = 16, color = "grey28",
angle = 90, hjust = c(1, 0.5, 0)
),
axis.ticks = ggplot2::element_line(color = "grey70", size = .4),
axis.ticks.length = grid::unit(.3, "lines"),
axis.ticks.y = element_blank(),
panel.grid.major.x = ggplot2::element_line(color = "white", size = .8),
panel.grid.major.y = element_blank(),
panel.grid.minor = ggplot2::element_blank(),
panel.background = ggplot2::element_rect(
fill = "grey96", color = "white", size = .8
),
plot.margin = margin(10, 20, 5, 5)
)
## titles
main <- "After catching up, the gap in the Latent Human Rights Protection Scores between the <span style='color:#9C4BFF;'>United States</span> and <span style='color:#28A87F;'>Germany</span> dramatically increased since 1999"
sub <- "The Latent Human Rights Protection Scores provides a measure focused on the protection of the physical integrity by taking into account torture, government killing, political imprisonment, extrajudicial executions, mass killings, and disappearances."
source <- "Data: Fariss, Kenwick & Reuning (2020) Latent Human Rights Protection Scores Version 4, doi: 10.7910/DVN/RQ85GK | via OurWorldInData"
## colors
colors <- c("#28A87F", "#9C4BFF")
fills <- desaturate(lighten(colors, .8), .3)
## visualization
ggplot() +
geom_braid(
data = rights_wide,
aes(x = year, ymin = DEU, ymax = USA, fill = DEU < USA)
) +
geom_vline(xintercept = 1999, linetype = "13", color = "grey28") +
geom_hline(yintercept = 0) +
geom_braid(
data = rights_wide,
aes(x = year, ymin = DEU, ymax = USA, fill = DEU < USA),
alpha = .8
) +
geom_line(
data = rights_long,
aes(x = year, y = rights, group = code),
color = "white",
size = 3.2
) +
geom_line(
data = rights_long,
aes(x = year, y = rights, color = code),
size = 1.2
) +
annotate(
geom = "text",
x = c(1959, 1983, 2012, 2017.7, 1998.7),
y = c(-.6, 2.45, 1.5, -.43, .7),
label = c(
"Until 1975, Germany\nalways scored higher\n than the United States",
"During the periods '75–'89 and '94/'95,\nthe United States even performed better",
"Germany takes\nthe lead again and\nthe gap increases",
"The United States\nfall below a score\nof 0 again in 2018", "1999"
),
color = c(colors[c(1,2,1,2)], "grey28"),
size = c(rep(6, 4), 5),
hjust = c(.5, .5, .5, 1, 1),
family = c(rep("Cabinet Grotesk S1 ExtraBold", 4), "Tabular"),
lineheight = .9
) +
scale_x_continuous(
breaks = c(1946, seq(1950, 2020, by = 5), 2019),
expand = c(0, 0)
) +
scale_y_continuous(
breaks = c(-.2, 0, .2),
labels = c("More abuse", "|", "More respect of human rights")
) +
scale_color_manual(values = colors, guide = "none") +
scale_fill_manual(values = fills, guide = "none") +
labs(title = main, subtitle = sub, caption = source, x = NULL, y = NULL)
ggsave("rights.png", width = 13, height = 8, bg = "white", dpi = 300)
@z3tt
Copy link
Author

z3tt commented Dec 29, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment