The Prison Policy Initiative has recently published a large bar chart on incarceration rates in each of the US states and in countries around the world, along with a description of the methodology of acquiring the data
OK….. so this highlights that US incarceration rates are the highest in the world, but a map or two might also be informative
Using the view source of the webpage, I was able to copy and paste the data used and save as a csv for processing
# load libraries
library(dplyr)
library(stringr)
library(tidyr)
library(leaflet)
library(rgdal)
# download the crude data
df <- read.csv("http://www.premiersoccerstats.com/incarcerationRatesCrude.csv")
print(glimpse(df))
## Observations: 222
## Variables: 4
## $ X..Country.State. (fctr) ['Louisiana', ['Mississippi', ['Oklaho...
## $ X.Incarceration.Rate. (int) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
## $ X.Incarceration.Rate.. (fctr) 1341], 1155], 1081], 1074], 1063], 106...
## $ X (lgl) NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,...
## NULL
# do some tidying up
names(df) <- c("region","intRate","usRate","y")
df <-df %>% select(region,intRate,usRate)
df$region <- str_sub(df$region,2)
df$region <- str_replace_all(df$region,"'","")
df$usRate <- df$usRate %>% extract_numeric()
## Produce a map of US states only
# subset dataset and set a color scale related to incarceration rate by state
dfUS <- df %>%
filter(intRate==0)
pal <- colorNumeric("Reds", c(0,max(dfUS$usRate)))
## Obtain standard shape files for US states
maps <- readOGR(
dsn = ".",
layer = "ne_50m_admin_1_states_provinces_lakes",
encoding = "UTF-8",verbose = FALSE
)
#limit to US states and DC
states <- maps[50:100,]
# merge map and data info
states2 <- sp::merge(
states,
dfUS,
by.x = "name",
by.y = "region",
sort = FALSE
)
# add a popup field
states2$popUp <-
paste0(
"<strong>",states2$name,"</strong><br>", states2$usRate," per 100,000"
)
# Produce map
states2 %>%
leaflet() %>%
addTiles() %>%
setView(-110,38,zoom = 3) %>%
addPolygons(
fillColor = ~ pal(usRate),
fillOpacity = 0.6,
color = "#BDBDC3",
weight = 1,
popup = ~ popUp
) %>%
mapOptions(zoomToLimits = "first") %>%
addLegend(pal = pal,
values = df$usRate,
position = "bottomleft",
title = "Incarceration rates",
labFormat = labelFormat(suffix = " per 100,000"))
Click on state for exact data
Now lets look at the world view. There was a lot of finicky work on country names etc. so I will not show the code
So clearly, the US is exceptional. The Prison Policy Initiative argue that incarceration should not be the default response to larger social problems but the range of legally-acceptable behaviour and crime-detection rates around the world should probably also be brought into the discussion