US Incarceration

Animated map (gganimate package), Dealing with missing data

Published

January 24, 2019

Notable topics: Animated map (gganimate package), Dealing with missing data

Recorded on: 2019-01-24

Timestamps by: Alex Cookson

View code

Screencast

Timestamps

facet_wrap

Creating a facetted (small multiples) line graph of incarceration rate by urbanicity and race over time

Discussion of statistical testing of incarceration rates by urbanicity (e.g., rural, suburban)

Exploring the extent of missing data on prison population

any

Using any function to filter down to states that have at least one (hence the any function) row of non-missing data

cut

Using cut function to manually bin data along user-specified intervals

Starting to create a choropleth map of incarceration rate by state

match

Using match function to match two-letter state abbreviation to full state name, in order to get data needed to create a map

Actually typing the code (now that we have the necessary data) to create a choropleth map

str_remove

Using str_remove function and regex to chop off the end of county names (e.g., "Allen Parish" becomes "Allen")

Making choropleth more specific by drilling down to county-level data

gganimate

Starting to make an animated choropleth map using gganimate

%%

Using modulo operator %% to choose every 5th year

scale_fill_gradient2

Using scale_fill_gradient2 function's limits argument to exclude unusally high values that were blowing out the scale

summarise_at

Using summarise_at function to apply the same function to multiple fields at the same time

Starting to investigate missing data (how much is missing, where is it missing, etc.)

Creating a line graph that excludes counties with missing data

Summary of screencast