Crime Analysts working with large crime data sets on a daily bases. Programs like R are powerful tools to organize and visualize their data for to uncover trends in crime for presentations, literature reviews, and investigative projects. The following Code-through will demonstrate simple ways R can be utilized to support crime analysis.
Concepts that will be explored include importing City crime data, filtering the data to narrow in on the type of crime in focus, and visualize that data to explore the changes in crime over the years. This walk through will be exploring 2020 through 2025 City of Chicago data.
Beyond the topic of crime, these fundamental processes can help anyone summarizes data sets that are too large for excel or other basic programs to handle. After this code-through you will be able to import, summarize and visualize your data.
Specifically, you’ll learn how to…
Find data
Import data
Filter data
Summarize data
Visualize data utilizing bar graph
The majority of Cities within the US have released their crime data since the early 2000s. For this code through we will be using data from Chicago Illinois.
Finding Data: A simple Google search of the city of interest and the key words Open Data will take you to the cities data portal site.
The following is the link to the crime data found on Chicago’s portal. https://data.cityofchicago.org/Public-Safety/Crimes-2001-to-Present/ijzp-q8t2/about_data
Importing Data After downloading your data set you will need to import it into your Rstudio document for further use. You will do this by assigning a title for you data set in RStudio.
#Importing Data into RStudio
data <- read.csv("Chicago_CrimeData.csv")
#A quick review of Data
head(data,10)Its exciting that we have such large data sets available to analyze but a key part of analyzing crime data is to narrowing down specific years, and characteristics of crime you want to review. Below we will utilize the filter() function to clean up our data that consist of all crime types between 2001 through 2026 to get a better idea of the Domestic Battery within Chicago during 2020 through 2025.
# Filter by year (2020 Through 2025)
crime_years <- data %>%
filter(Year >= 2020 & Year <= 2025)
#Filter by Primary Crime Type: Battery
battery_data <- crime_years %>%
filter(Primary.Type == "BATTERY")
#Filter by Secondary Crime Type: Domestic Battery
domestic_battery <- battery_data %>%
filter(Description == "DOMESTIC BATTERY SIMPLE")
#Review of Data
head(domestic_battery,10)Now that we have our data filtered to show all domestic battery incidents within 2020 through 2025; we will will take a look at how the total number of incidents have changed over the years.
# Incident Count by Year
year_totals <- domestic_battery %>%
group_by(Year) %>%
summarize(Total_Incidents = n())
year_totalsNICE! By looking at the chart above, we can see that 2020 had the highest number of incidents within the six-year period, while 2022, just two years later, had the lowest. Without doing anything else, this provides an overview of our data. However, it can be difficult to analyze incident totals when they are presented only in a table. To create a clearer visual for interpretation, we will next create a bar graph.
If you were left thinking, “Well, that’s no fun. The data looks almost the same every year,” I understand the initial disappointment. However, for crime analysts, this would actually be a pretty interesting finding.
Think about the years selected for this analysis: 2020 through 2025. During much of this period, communities were dealing with the social and economic impacts of the COVID-19 pandemic. With so many changes to daily life, employment, and social interactions, many people might expect to see major changes in crimes involving interpersonal conflict, such as domestic battery.
Instead, the data shows only minor fluctuations from year to year. Despite everything that was happening during this period, reported domestic battery incidents remained close to 20,000 cases annually. This suggests that domestic battery is a persistent issue within Chicago rather than a problem that rises and falls with short-term societal changes.
For crime analysts, findings like this can be just as important as discovering a dramatic increase or decrease in crime. The results suggest that domestic battery remains a long-term public safety concern and highlight the importance of continued victim services, prevention programs, and community support resources.
Chicago Open Data Portal https://data.cityofchicago.org
dplyr Documentation https://dplyr.tidyverse.org
ggplot2 Documentation https://ggplot2.tidyverse.org