title: “Violent Crime in Philadelphia During the Pandemic (2020–2022)” author: “Maverick J. Borelli” date: “3/20/26”

Overview

Dataset Description

For this project, I used a crime dataset from the Philadelphia Police Department through OpenDataPhilly. The dataset includes information on when crimes happened, what type of crime occurred, and where each incident took place.

There is also a codebook included with the dataset that explains the variables, like crime categories, location data, and timestamps. This made it easier for me to understand and work with the data correctly.

Source

Philadelphia Police Department
https://phl.carto.com

The data was collected by the Philadelphia Police Department to monitor crime activity and make information available to the public.

Load Data

crime_data_1 <- read_csv("incidents_part1_part2.csv", show_col_types = FALSE)
crime_data_2 <- read_csv("incidents_part1_part2 (1).csv", show_col_types = FALSE)
crime_data_3 <- read_csv("incidents_part1_part2 (2).csv", show_col_types = FALSE)

crime_data <- bind_rows(crime_data_1, crime_data_2, crime_data_3)

Data Preparation

To get the dataset ready, I had to combine the files, clean up the date column, and create variables for year and quarter. I also filtered the data to only include violent crimes and removed any missing location values so I could map everything correctly.

crime_data$date <- as.Date(crime_data$dispatch_date_time)

crime_data$year <- year(crime_data$date)
crime_data$quarter <- quarter(crime_data$date)

violent_crime <- crime_data %>%
  filter(year >= 2020 & year <= 2022) %>%
  filter(text_general_code %in% c(
    "Aggravated Assault",
    "Robbery",
    "Homicide - Criminal"
  )) %>%
  filter(!is.na(lat), !is.na(lng))

violent_crime$year_quarter <- paste0(year(violent_crime$date), "-Q", quarter(violent_crime$date))

Graph 1: Violent Crimes by Year

ggplot(violent_crime, aes(x = factor(year))) +
  geom_bar(fill = "darkblue") +
  theme_minimal() +
  labs(
    title = "Total Violent Crimes by Year",
    x = "Year",
    y = "Number of Crimes"
  )

This graph shows how many violent crimes happened each year from 2020 to 2022. I included it to get a general idea of whether crime was increasing, decreasing, or staying about the same.

Daily Crime Counts

daily_crime_counts <- violent_crime %>%
  group_by(date) %>%
  summarise(total_crimes = n())

Graph 2: Violent Crime Over Time

ggplot(daily_crime_counts, aes(x = date, y = total_crimes)) +
  geom_point(alpha = 0.5, color = "red") +
  theme_minimal() +
  labs(
    title = "Violent Crime Over Time (2020–2022)",
    x = "Date",
    y = "Number of Crimes"
  )

This graph shows daily crime counts over time. I used it to look for patterns, trends, or any noticeable spikes.

Graph 3: Violent Crime by Quarter

ggplot(violent_crime, aes(x = year_quarter)) +
  geom_bar(fill = "steelblue", color = "black") +
  theme_minimal() +
  labs(
    title = "Violent Crimes by Quarter",
    x = "Year-Quarter",
    y = "Number of Crimes"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

This breaks the data into quarters so I could compare different parts of each year and see if certain times had more crime.

Graph 4: Crime Type Distribution

ggplot(violent_crime, aes(x = text_general_code)) +
  geom_bar(fill = "purple") +
  coord_flip() +
  theme_minimal() +
  labs(
    title = "Distribution of Violent Crime Types",
    x = "Crime Type",
    y = "Count"
  )

This shows how common each type of violent crime is. I included it to understand which crimes happen the most.

Graph 5: Map of Crime Locations

philly_map <- map_data("county") %>%
  filter(region == "pennsylvania", subregion == "philadelphia")

ggplot() +
  geom_polygon(
    data = philly_map,
    aes(x = long, y = lat, group = group),
    fill = "gray90",
    color = "black"
  ) +
  geom_point(
    data = violent_crime,
    aes(x = lng, y = lat),
    alpha = 0.15,
    color = "darkred",
    size = 0.5
  ) +
  coord_quickmap() +
  theme_minimal() +
  labs(title = "Map of Violent Crime Incidents in Philadelphia")

This map shows where crimes happened across the city. It helped me see whether crime is spread out or clustered in certain areas.

Impact of Visualization

The graphs made it much easier to understand the data compared to just looking at raw numbers. I was able to quickly see that crime levels stayed fairly consistent and also get a better sense of how crime is distributed over time and location.

Prediction

Based on what I saw, violent crime seems to stay within a similar range over time, with normal fluctuations. There isn’t a strong upward or downward trend, so it’s hard to make precise predictions. However, I would expect crime to continue at similar levels unless something major changes.

Conclusion

Overall, violent crime in Philadelphia stayed relatively consistent from 2020 to 2022. There are normal ups and downs, but no major long-term increase or decrease. Crime also appears to be spread throughout the city rather than concentrated in just one place.

Reflection

What was easy: Once the data was cleaned, making graphs and organizing everything was pretty straightforward.

What was difficult: The hardest part was preparing the data, especially combining files and working with dates.

References

Philadelphia Police Department. OpenDataPhilly Crime Dataset
https://phl.carto.com

Weisburd, D., et al. (2004). Trajectories of crime at places.

FBI Uniform Crime Reporting Program
https://www.fbi.gov/services/cjis/ucr

Bureau of Justice Statistics
https://bjs.ojp.gov