Death penalty

[This article was first published on r.iresmi.net, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Death Valley Winter

Death Valley Winter – CC-BY by street.light

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}.

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}.

codes <- tribble(
  ~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")
  
  cdpd <- read_xlsx("cdpd.xlsx") |> 
    clean_names() |> 
    filter(year == 2022,
           country != "MICRONESIA") |> 
    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 {
  cdpd <- read_rds("cdpd.rds")
}

abolished <- nrow(filter(cdpd, lib_deathpenalty == "Abolished")) / nrow(cdpd)

Map data

country_map <- ne_countries(scale = 110, returnclass = "sf") |> 
  select(sovereignt, sov_a3, admin, adm0_a3)

Map

pal_dp <- codes |> 
  select(lib_deathpenalty, color) |> 
  deframe()

cdpd_map <- country_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: NaturalErth
                       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"))

A map of World death penalty status : death penalty is still retained in 44% of the countries

World death penalty status

References

Anckar, Carsten, and Thomas Denk. 2024. Comparative Death Penalty Database.” Harvard Dataverse. https://doi.org/10.7910/DVN/LI3WYK.
To leave a comment for the author, please follow the link and comment on their blog: r.iresmi.net.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)