title: “Interactive Arrest Map” output: html_document date: “2026-05-06” —{r} rm(list = ls()) getwd() setwd(“/Users/devonlucky/Downloads/Rfolder”) getwd() rm(list = ls()) library(ggplot2) library(tidyverse) library(colorify) library(haven)
state_crime <- read_csv(“arrests_by_state-2010-2024.csv”, skip = 1) View(state_crime)
crime_2024 <- state_crime %>% filter(year == 2024) %>% group_by(state) %>% summarize(total_arrests = sum(arrests, na.rm = TRUE))
crime_2024
library(sf) library(rnaturalearth) library(rnaturalearthdata)
usa <- ne_download( scale = 50, type = “states”, category = “cultural”, returnclass = “sf” ) %>% filter(admin == “United States of America”)
usa
final_data <- usa %>% left_join(crime_2024, by = c(“name” = “state”))
final_data %>% select(name, total_arrests)
ggplot(final_data) + geom_sf(aes(fill = total_arrests), color = “white”, size = 0.2) + scale_fill_viridis_c( name = “Total Arrests”, labels = scales::label_comma(), na.value = “gray” ) + labs( title = “Figure 1: Total Arrests by State in 2024”, subtitle = “State-level arrest totals across the United States”, caption = “Note: Florida is gray because it is missing from the arrest dataset.: Arrests by States (2010-2024) dataset.” ) + theme_void() + theme(plot.caption = element_text(hjust = 0))
library(mapview) library(leaflet) library(htmlwidgets)
interactive_arrest_map <- mapview(final_data, zcol = “total_arrests”) interactive_arrest_map
mapshot(interactive_arrest_map, url = “arrests_2024_interactive.html”)
saveWidget(interactive_arrest_map@map, file = “arrests_2024_interactive.html”, selfcontained = TRUE)