Skip to content

Instantly share code, notes, and snippets.

@tor-gu
Created March 17, 2022 15:35
Show Gist options
  • Save tor-gu/c0cdd91a58b1e81d8cf46b20f139b53c to your computer and use it in GitHub Desktop.
Save tor-gu/c0cdd91a58b1e81d8cf46b20f139b53c to your computer and use it in GitHub Desktop.
Video footage of use of force incidents in NJ counties
library(tidyverse)
library(lubridate)
library(njoaguof)
# Get number proportion of incidents with body worn camera or any video
# by county and by 4-month interval
# devtools::install_github("tor-gu/njoaguof")
video_by_county <- incident %>%
left_join(incident_video_type) %>%
select(form_id,
date = incident_date_1,
county = incident_municipality_county,
video_footage,
video_type) %>%
mutate(
period = case_when(
between(date, ymd("2020-10-01"), ymd("2021-01-31")) ~ 1L,
date < "2021-06-01" ~ 2L,
date < "2021-10-01" ~ 3L,
date < "2022-02-01" ~ 4L,
TRUE ~ NA_integer_
)
) %>% filter(!is.na(period),!is.na(county)) %>%
group_by(county, period) %>%
summarize(
total = n_distinct(form_id),
`Body Worn Camera` = sum(video_type == "Body Worn", na.rm = TRUE) /
total,
`Any Video` = n_distinct(form_id[video_footage == "Yes"]) /
total
) %>%
ungroup() %>%
pivot_longer(cols = `Body Worn Camera`:`Any Video`,
names_to = "video_type",
values_to = "rate")
# Prepare the labels for the faceting
video_by_county <- video_by_county %>%
mutate(period_label = factor(
case_when(
period == 1 ~ "10/20 - 1/21",
period == 2 ~ " 2/21 - 5/21",
period == 3 ~ " 6/21 - 9/21",
period == 4 ~ "10/21 - 1/22",
)
)) %>%
mutate(period_label = fct_reorder(period_label, period)) %>%
mutate(video_type = factor(video_type, levels =
c("Body Worn Camera", "Any Video")))
# Get the New Jersey county map and plot
library(tigris)
options(tigris_use_cache = TRUE)
county_map <- counties(state = "New Jersey", class = "sf")
library(tmap)
county_map %>%
geo_join(video_by_county,
by_sp = "NAME",
by_df = "county",
how = "inner") %>%
tm_shape() +
tm_polygons("rate", title = "Rate", style = "cont") +
tm_facets(c("video_type", "period_label"),
free.scales = FALSE) +
tm_layout(
main.title = "NJ police use of force incidents\nvideo footage availabilty",
main.title.size = 1.1,
legend.format = list(
fun = function(x)
paste0(formatC(
100 * x, digits = 0, format = "f"
), " %")
)
) +
tm_credits(c(rep("", 7), "US Census\nNJ OAG"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment