Day 3 of 30DayMapChallenge: « Polygons » (previously).
A classic world choropleth map. We’ll use the Comparative Death Penalty Database (Anckar and Denk 2024) available on https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/LI3WYK and the basemap from {rnaturalearth} to map countries by death penalty status.
library(dplyr)
library(tibble)
library(readr)
library(glue)
library(readxl)
library(janitor)
library(ggplot2)
library(scales)
library(ggspatial)
library(sf)
library(rnaturalearth)
library(countrycode)
Data
The CDPD doesn’t use ISO A3 country codes, so we need to translate them from the Correlates of War codes with {countrycode}. Three countries need manual adjustments.
<- tribble(
codes ~deathpenalty, ~lib_deathpenalty, ~color,
0, "Abolished", "lightskyblue",
1, "Abolished for ordinary crimes only", "khaki1",
2, "Abolished for ordinary crimes only, but used during the last 10 years.", "gold1",
3, "Abolished in practice", "indianred1",
4, "Retained", "indianred4")
if (!file.exists("cdpd.rds")) {
download.file("https://dataverse.harvard.edu/api/access/datafile/10251764",
"cdpd.xlsx")
<- read_xlsx("cdpd.xlsx") |>
cdpd clean_names() |>
filter(year == 2022) |>
mutate(iso = countrycode(cowcode, "cown", "iso3c",
custom_match = c("342" = "SRB",
"348" = "MNE",
"818" = "VNM"))) |>
left_join(codes, join_by(deathpenalty)) |>
select(country, iso, lib_deathpenalty) |>
write_rds("cdpd.rds")
else {
} <- read_rds("cdpd.rds")
cdpd
}
<- nrow(filter(cdpd, lib_deathpenalty == "Abolished")) / nrow(cdpd) abolished
Map data
The easy to use dataset from Natural Earth.
<- ne_countries(scale = 110, returnclass = "sf") |>
country_map select(sovereignt, sov_a3, admin, adm0_a3)
Map
<- codes |>
pal_dp select(lib_deathpenalty, color) |>
deframe()
<- country_map |>
cdpd_map left_join(cdpd, join_by(adm0_a3 == iso))
|>
cdpd_map ggplot() +
geom_sf(aes(fill = lib_deathpenalty)) +
scale_fill_manual(values = pal_dp, na.value = "grey") +
coord_sf(crs = "+proj=eqearth") +
labs(title = glue("Death penalty is still retained in {percent(1 - abolished)} of the countries"),
subtitle = "2022",
fill = "Death penalty\nstatus",
caption = glue("data: Comparative Death Penalty Database
map data: Natural Earth
r.iresmi.net - {Sys.Date()}")) +
theme_void() +
theme(plot.background = element_rect(color = NA, fill = "white"),
legend.position = "bottom",
legend.text = element_text(size = 8),
plot.caption = element_text(size = 5,
color = "darkgrey"))
References
Anckar, Carsten, and Thomas Denk. 2024. “Comparative Death Penalty Database.” Harvard Dataverse. https://doi.org/10.7910/DVN/LI3WYK.