The data set that I am using for Assignment 1 details crime in Baltimore City from 2013 - 2023 (year-to-date). The raw data is available on Baltimore City’s Open Baltimore database: https://data.baltimorecity.gov/datasets/part-1-crime-data/explore. As a resident of Baltimore City, I was interested in learning more about recent crime statistics and trends.
Baltimore Crime by Type and Year (2013-2023): At a high level, the total number of incidents in Baltimore City decreased during the COVID-19 pandemic years, but have been since steadily rising. I also noticed a large uptick in Auto Thefts in the city. This is likely attributed to the recently discovered car theft vulnerability that plague push-to-start Kia and Hyundai models. As of Oct 2023, Baltimore is on pace for a nearly 190% increase in Auto Thefts year over year.
Baltimore Crime by Hour (2013-2023): This visualization plots the number of incidents against hours in a day. Baltimore Crime tends to peak at 1800 hours and bottom at 0500 hours.
Baltimore Crime by Description and District (2013-2023): Baltimore City is divided into nine districts. This visualization explores crime descriptions as a percentage of all crime in each district. We can see that certain crimes are more common in certain districts between 2013 and 2023.
Baltimore Crime Severity by District (2013-2023): As
part of my dive into Baltimore City crime, I wanted to parse out the
“severity” level of the offenses in each district. Incidents involving
property were bucketed separately to incidents involving persons:
Property Crime = Arson, Auto Theft, Burglary, Larceny, Robbery;
Violent Crime = Agg. Assault, Common Assault, Homicide, Rape, Shooting;
Baltimore Crime Heat Map (2013-2023): To get a better idea of crime incident hot spots in the city, I plotted all ten years of data using a Heat Map. I immediate recognized a few of the hot spots as the following: Neighborhoods North of Patterson Park, Downtown/Inner Harbor, The Horseshoe Casino, Cross Street Market / Heart of Federal Hill, etc.
Baltimore Crime by Weekday (2013-2023): This visualization explores the tendencies of certain types of incidents to occur on certain days of the week. Notably, over the last 10 years, you are more likely to be burglarized during the week than on the weekends. In addition, I noticed that violent crimes tend to peak during the weekend days (Agg. Assault, Common Assault, Shootings, etc).
#Bar Graph Construction---------------------------------------------------------
ggplot(final_df, aes(x = year, y = n, fill = Description)) +
geom_bar(stat = "identity") +
labs(title = "Baltimore Crime by Type by Year (2013-2023)", x = "Year",
y = "Crime Counts", caption ="Source: Baltimore City's Open Baltimore: https://data.baltimorecity.gov/datasets") +
theme_light() +
theme(plot.title = element_text(hjust = 0.5)) +
scale_fill_brewer(palette="RdYlBu") +
scale_y_continuous(labels = comma) +
scale_x_continuous(labels = x_axis_labels, breaks = x_axis_labels)
#Line Graph Construction--------------------------------------------------------
ggplot(hours_df, aes(x = hour24, y = n)) +
geom_line(color = 'black', size = 1) +
geom_point(shape=21, size=2, color='darkblue', fill='darkblue') +
labs(x="Hour", y="Incident Count", title ="Baltimore Crime by Hour (2013-2023)",
caption ="Source: Baltimore City's Open Baltimore: https://data.baltimorecity.gov/datasets") +
scale_y_continuous(labels=comma) +
theme_light() +
theme(plot.title = element_text(hjust = 0.5)) +
scale_x_continuous(labels=x_axis_labels_hr, breaks = x_axis_labels_hr, minor_breaks = NULL) +
geom_point(data = hi_lo, aes(x = hour24, y = n), shape=15, linewidth = 3, fill='red', color='red') +
geom_label_repel(aes(label= ifelse(n==max(n) | n==min(n), scales::comma(n), "")),
nudge_x = 1.25,
box.padding = 1,
size=4,
color='Grey50',
segment.color = 'darkblue')
x_axis_labels_hr = min(hours_df$hour24):max(hours_df$hour24)
ggplot(data = district_df_final, aes(x = "", y = n, fill = Description)) +
geom_bar(stat="identity", position = "fill") +
coord_polar(theta="y", start=0) +
labs(fill = "Crime Descriptions", x = NULL, y = NULL, title = " Baltimore Crime Description by District (2013-2023)",
caption = "Slices under 3% are not labeled")+
theme_light() +
theme(plot.title = element_text(hjust = 0.5),
axis.text = element_blank(),
axis.ticks = element_blank(),
panel.grid = element_blank()) +
scale_fill_brewer(palette = "RdYlBu") +
geom_text(aes(x = 1.7, label = ifelse(percent_of_total > 3, paste0(percent_of_total, "%"), "")),
size = 3.0,
position = position_fill(vjust = 0.5)) +
facet_wrap(~District, ncol=3, nrow=3)
ggplot(data = df_pie_crime_final, aes(x = "", y = n, fill = Description)) +
geom_bar(stat="identity", position = "fill") +
coord_polar(theta="y", start=0) +
labs(fill = "Crime Descriptions", x = NULL, y = NULL, title = " Baltimore Crime Severity by District (2013-2023)",
caption = "Source: Baltimore City's Open Baltimore: https://data.baltimorecity.gov/datasets")+
theme_light() +
theme(plot.title = element_text(hjust = 0.5),
axis.text = element_blank(),
axis.ticks = element_blank(),
panel.grid = element_blank()) +
scale_fill_brewer(palette = "Reds") +
geom_text(aes(x = 1.7, label = ifelse(percent_of_total > 3, paste0(percent_of_total, "%"), "")),
size = 3.0,
position = position_fill(vjust = 0.5)) +
facet_wrap(~District, ncol=3, nrow=3)
m = leaflet() %>%
addProviderTiles(providers$OpenStreetMap) %>%
setView(lng = -76.61219, lat = 39.29038, zoom = 12) %>%
addHeatmap(lng = df_heat_final$Longitude, lat = df_heat_final$Latitude, blur = 4, max = 500, radius = 5)
m