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)

Data Set

Arrests by States (2010-2024)

Source: https://data.dathere.com/dataset/5ba9397c-0610-4578-8451-6f9cdba85aea/resource/56538067-2d22-4ca4-8706-e728094bd5bb/download/arrests_by_state-2010-2024.csv

state_crime <- read_csv(“arrests_by_state-2010-2024.csv”, skip = 1) View(state_crime)

Filtering the dataset to only include 2024 arrests.

And I grouped the data by state and add together all arrest totals.

This creates one total arrest number for each state.

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

Merging the arrest data with the US Map

final_data <- usa %>% left_join(crime_2024, by = c(“name” = “state”))

final_data %>% select(name, total_arrests)

Choropleth

Florida is missing its 2024 data, it showed up as NA

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))

This choropleth map shows total arrests by state in 2024.

States with lighter colors have higher arrest totals, while darker states have lower totals.

California and Texas have the highest arrest totals, while smaller states have fewer arrests.

Florida is gray because its arrest data was missing from the dataset.

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(, file = “arrests_2024_interactive.html”, selfcontained = TRUE)