This dataset is a detailed description of all arrests made in Montgomery County, Maryland, updated daily. These descriptions include date and time, a description of categories ranging from assault to drug offenses, and location in relation to police district and city. The dataset is from data.montgomerycountymd.gov, a dataset repository for all things pertaining to Montgomery County. I read over and filtered this dataset to focus on drug related crimes, as well as mutated a new column containing the frequency of certain crimes in each police district. I chose this topic because drug related crimes seem to be very frequent and publicly visible in Montgomery County.
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.4.4 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.0
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(plotly)
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
setwd("/Users/cynthiahall/Downloads/DATA 110")CrimeMC <-read.csv("Crime_20240410.csv")#find crime totals for drug crimesCrime <- CrimeMC %>%group_by(Crime.Name3) %>%mutate(CrimeCount =n()) %>%ungroup() %>%filter(Crime.Name2 =="Drug/Narcotic Violations")#totals of all drug related crimesggplot(Crime, aes(x =`Crime.Name3`, y = CrimeCount)) +geom_bar(stat ="identity", fill ="skyblue") +labs(title ="Total Counts by Crime Category", x ="Offense", y ="Total Count") +theme(axis.text.x =element_text(angle =45, hjust =1))
#The p-values associated with the coefficients are very low (nearly zero), indicating that there is strong evidence to reject the null hypothesis that the coefficients are zero. In other words, Police.District.Name is a significant predictor of CrimeCount. The adjusted R-squared value is 0.02332, suggesting that the model explains about 2.3% of the variance in CrimeCount. This is relatively low, indicating that Police.District.Name alone may not be sufficient to explain the variation in crime counts.lm <-lm(`CrimeCount`~ Police.District.Name, data = Crime)summary(lm)
Call:
lm(formula = CrimeCount ~ Police.District.Name, data = Crime)
Residuals:
Min 1Q Median 3Q Max
-12480 -8807 4616 4702 9780
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 6780 1506 4.501 6.8e-06 ***
Police.District.NameBETHESDA 5703 1515 3.765 0.000167 ***
Police.District.NameGERMANTOWN 3932 1512 2.601 0.009307 **
Police.District.NameMONTGOMERY VILLAGE 2544 1510 1.685 0.092011 .
Police.District.NameROCKVILLE 2720 1512 1.799 0.072087 .
Police.District.NameSILVER SPRING 5163 1509 3.422 0.000623 ***
Police.District.NameTAKOMA PARK 4265 1545 2.760 0.005777 **
Police.District.NameWHEATON 5078 1509 3.364 0.000769 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 7379 on 25608 degrees of freedom
Multiple R-squared: 0.0245, Adjusted R-squared: 0.02424
F-statistic: 91.89 on 7 and 25608 DF, p-value: < 2.2e-16
Information found in this WTOP News article states that overall crime rates in Montgomery County have risen for the third year in a row, in almost all categories. Auto thefts spiked by 131%, carjackings rose by 28.6% crimes under the category “crimes against society,” including drug offenses, fell by 13.8%, and crimes under the category “crimes against persons,” including homicides, rose 6.6%. (https://wtop.com/montgomery-county/2024/02/crime-increased-in-montgomery-county-for-third-straight-year-data-shows/)
#top 5 drug related crimesTop5 <- Crime %>%count(`Crime.Name3`, sort =TRUE) %>%head(5)Top5
#top 3 districts in relation to crimes committedTopDistricts <- Crime %>%count(Police.District.Name, sort = T) %>%head(3)TopDistricts
# A tibble: 3 × 2
Police.District.Name n
<chr> <int>
1 SILVER SPRING 6567
2 WHEATON 5710
3 MONTGOMERY VILLAGE 4675
#Filtering to only include the top 5 drug crimes and top 3 districts found aboveTopCrime <- Crime %>%filter(Crime.Name3 %in%c("DRUGS - MARIJUANA - POSSESS","DRUGS - COCAINE - POSSESS","DRUGS - OPIUM OR DERIVATIVE - POSSESS","DRUGS - MARIJUANA - SELL","DRUGS - COCAINE - SELL")) %>%filter(Police.District.Name %in%c("SILVER SPRING","WHEATON","MONTGOMERY VILLAGE"))#setting individual colors CrimeColors <-c("DRUGS - COCAINE - POSSESS"="#000066","DRUGS - COCAINE - SELL"="#0000cc","DRUGS - MARIJUANA - POSSESS"="#0066cc","DRUGS - MARIJUANA - SELL"="#00ccFF","DRUGS - OPIUM OR DERIVATIVE - POSSESS"="#66ffff")#Find and mutate a column representing the total number of occurances for each top 5 drug crime, in relation to police districtCrime <- TopCrime %>%group_by(Police.District.Name, Crime.Name3) %>%mutate(District.Count =n()) %>%ungroup()Top5.3<-ggplot(Crime, aes(x = Crime.Name3, y = District.Count, fill = Crime.Name3, text =paste("Crime.Name3:", Crime.Name3, "<br>District.Count:", District.Count))) +geom_bar(stat ="identity") +labs(title ="Most Common MoCo Districts For Crime, and Their Top 3 Drug Offenses", x ="Offense",y ="Totals", caption ="Source: https://data.montgomerycountymd.gov") +scale_fill_manual(values = CrimeColors) +theme(axis.text.x =element_text(angle =20, hjust =1)) +facet_wrap(~Police.District.Name) +theme(axis.text.y =element_blank(), axis.text.x =element_blank())plotly <-ggplotly(Top5.3, tooltip =c("x", "y"))plotly
This visualization represents the five most common drug related crimes (DRUGS - MARIJUANA - POSSESS, DRUGS - COCAINE - POSSESS, DRUGS - OPIUM OR DERIVATIVE - POSSESS, DRUGS - MARIJUANA - SELL, DRUGS - COCAINE - SELL), and the total arrests made for each one, in relation to the three police districts with the highest crime rates (SILVER SPRING, WHEATON, MONTGOMERY VILLAGE).