Dataset Intro
For module 1, I chose a dataset pertaining to Chicago crime in 2021. This dataset, from Dr. Tallon's list of RealWorldDatasets includes variables all relating to crime incidents including the type of crime, description of the crime, date/time, if the suspect was arrested, location of the crime, ward number, district number, community area, and longitude and latitude to name a few. Some other variables in the dataset included case numbers, partial street addresses, ID numbers, case numbers, FBI codes. In total this dataset has around 203k observations with 22 variables, not including the variables I added for my analysis.
library(ggplot2)
library(scales)
library(ggthemes)
library(lubridate)
library(dplyr)
ChicagoCrime <- read.csv("C:/Users/jack/OneDrive/Desktop/IS460 - O/Crimes 2021.csv", header = TRUE)
Visualization 1 - Frequency of Crime by Chicago Ward
For my first visualization, I wanted to investigate the frequency of crimes committed by ward. This allows us to determine which ward has the highest amount of crime and therefore is the most dangerous. Once I ran my histogram, the ward with the highest crime frequency was 28 followed by wards 27 and 42. The ward with the highest amount of crime in Chicago is ward 28 at roughly 9000 incidents.
# Creates labels under each ward bin
x_axis_labels = min(ChicagoCrime$Ward, na.rm = TRUE):max(ChicagoCrime$Ward, na.rm = TRUE)
# Histogram of Chicago Crime freq by ward
ggplot(ChicagoCrime, aes(x = Ward)) +
geom_histogram(binwidth = 0.5, fill = "lightblue", color = "black") +
labs(title = "Frequency of 2021 Chicago Crime by Ward", x = "Chicago Ward Number", y = "Crime Frequency")+
theme_clean() +
theme(plot.title = element_text(hjust = 0.5)) +
scale_x_continuous(labels = x_axis_labels,
breaks = x_axis_labels, minor_breaks = NULL)

Visualization 2 - Frequency of 2021 Chicago Crime with Arrest vs
Crime without Arrest
For my second visualization, I created a barchart to investigate whether crimes in Chicago resulted in arrest (true) or non-arrest (false) using the arrest variable. Examining the outputted barchart, most crime incidents overwhelmingly did not result in arrest. Around 175k indicents were non-arrestable crimes whle around 25k crimes resulted in arrest.
ggplot(ChicagoCrime, aes(x = Arrest)) +
geom_bar(fill = "darkgreen", color = "black") +
labs(title = "Frequency of 2021 Chicago Crime with Arrest vs Crime without Arrest ",
x = "Crime Resulted in Arrest (True of False)", y = "Frequency of Crimes")+
theme_calc() +
theme(plot.title = element_text(hjust = 0.5))

Visualization 3 - Frequency of Crime Types in Chicago
I thought it would be interesting to investigate which category of crime in Chicago is the most popular along with the frequency of that crime. In the data, crimes are separated different categories using the "Primary.Type" variable. Examining the output, battery and theft seem to be neck and neck. Changing the scale of this data would allow us to see which one is actually the most dangerous but shifting this scale makes it more challening to see the frequency of less-committed crimes, so I decided to leave it alone to not make the other data more challengning to interpret. Besides battery and theft, which are both over 40k in frequency, criminal damage seems to be the third most frequent category of crime at about 25k incidents. Assault comes in fourth place at about 20k crime incidents.
ggplot(ChicagoCrime, aes(x = Primary.Type)) +
geom_bar(fill = "orange", color = "black", ) +
labs(title = "Frequency of 2021 Chicago Crime by Crime Type", x = "Crime Type", y = "Crime Frequency")+
theme_clean() +
theme(axis.text.x = element_text(angle = 60, vjust = 1, hjust = 1),
plot.title = element_text(hjust = 0.5))

Visualization 4 - Frequency of Crimes Committed by Month
For this plot, I wanted to investigate how the date category related to crime, specifically by looking at the number of crimes that occured in each month. To accomplish this I first had to extract the month from the "Date" variable and then used that to create a standalone "month" variable that ranged from 0 to 12 for the number of months in a year. Being that this dataset only includes 2021 data, I did not need to extract the year. I extracted a few other variables from "Date" such as the hour and minute in case I wanted to use them for future analysis. I created a histogram with 12 bins to represent the months of the year. Looking at the output, the month with the highest frequency of crime is narrowly 10 which is October at rougly 18.5k crimes. This is closely followed by 9 which is September and then 7 which is July. Therefore, the month with the highest frequency of crime committed in Chicago in 2021, was October.
# extracts variables from "Date" variable using Lubridate
ChicagoCrime$DateTime <- mdy_hm(ChicagoCrime$Date)
ChicagoCrime$month <- month(ChicagoCrime$DateTime)
ChicagoCrime$hour <- hour(ChicagoCrime$DateTime)
ChicagoCrime$minute <- minute(ChicagoCrime$DateTime)
ggplot(ChicagoCrime, aes(x = month)) +
geom_histogram(bins = 12, fill = "lightgreen", color = "darkgreen") +
labs(title = "Frequency of 2021 Chicago Crime by Month", x = "Month Number", y = "Crime Frequency") +
theme_economist_white() +
theme(plot.title = element_text(hjust = 0.5)) +
scale_x_continuous(breaks = seq(from = 0, to = 12, by = 1)) +
scale_y_continuous(breaks = seq(0, 20000, 2500), lim = c(0, 20000))

Visualization 5 - Crime Committed by Hour
For my final visualization, I decided to once again investigate time relating to crime. I wanted to see which times of the day, broken up by hours have the highest density of crime incidents. Since I was able to extract the hour from the "Date" column in my last visualization, I did not need to recode that step. My x-axis scale is broken up into 24 segments to depict the 24 hours in a day. Lokoing at the output, there is a steep inclinatino of crime between 12am and 1am at a density of slightly over 0.08. This dramatically drops off as the morning continues, potentially due to sleep then once again rises around 12pm to a density of about 0.05. There are small ridges indicating small increases in crime density around other hours in the early afternoon but are not as clear of a pattern as midnight and lunch time.
ggplot(ChicagoCrime, aes(x = hour)) +
geom_density(color = "darkred", size = 1.5) +
labs(title = "Density of Crime in Chicago by Hour", x = "Hour", y = "Density") +
theme(plot.title = element_text(hjust = 0.5)) +
theme_pander() +
scale_x_binned(breaks = seq(from = 0, to = 24, by = 1))
