Project 2

Author

Zachary Rodavich

For Project 2, I will be visualizing crimes committed in Rockville, MD, using an open-source dataset provided by Montgomery County. This dataset will focus on a select set of crimes, and will concentrate on determining where crimes occur most in Rockville, and which crimes are the most often commited.

Step 1. Setting Everything Up

#Loading the required libraries
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.0     ✔ readr     2.1.6
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.2     ✔ tibble    3.3.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.2
✔ purrr     1.2.1     
── 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(tidyr)
library(leaflet)
library(ggthemes)
library(ggplot2)
library(maps)

Attaching package: 'maps'

The following object is masked from 'package:purrr':

    map
#Setting the working directory
getwd()
[1] "/Users/zacharyrodavich/Downloads"

Step 2. Reading the CSV File

#Reaading the CSV file
mococrimes <- read_csv("Crime_20260421.csv")
Rows: 11182 Columns: 30
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (22): Dispatch Date / Time, Start_Date_Time, End_Date_Time, NIBRS Code, ...
dbl  (8): Incident ID, Offence Code, CR Number, Victims, Zip Code, Address N...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#Showing the dataset
mococrimes
# A tibble: 11,182 × 30
   `Incident ID` `Offence Code` `CR Number` `Dispatch Date / Time`
           <dbl>          <dbl>       <dbl> <chr>                 
 1     201571503           9101   260016574 04/18/2026 03:26:05 AM
 2     201571500           9101   260016573 04/18/2026 01:49:43 AM
 3     201571493           9113   260016563 04/17/2026 10:43:35 PM
 4     201571492           9199   260016564 04/17/2026 10:35:13 PM
 5     201571496           1399   260016568 04/18/2026 12:28:58 AM
 6     201571504           9061   260016560 04/17/2026 09:31:22 PM
 7     201571476           5309   260016554 04/17/2026 09:14:00 PM
 8     201571488           5707   260016552 04/17/2026 08:48:56 PM
 9     201571490           1399   260016559 04/17/2026 09:43:56 PM
10     201571478           9199   260016526 04/17/2026 07:18:59 PM
# ℹ 11,172 more rows
# ℹ 26 more variables: Start_Date_Time <chr>, End_Date_Time <chr>,
#   `NIBRS Code` <chr>, Victims <dbl>, `Crime Name1` <chr>,
#   `Crime Name2` <chr>, `Crime Name3` <chr>, `Police District Name` <chr>,
#   `Block Address` <chr>, City <chr>, State <chr>, `Zip Code` <dbl>,
#   Agency <chr>, Place <chr>, Sector <chr>, Beat <chr>, PRA <chr>,
#   `Address Number` <dbl>, `Street Prefix` <chr>, `Street Name` <chr>, …

Step 3. Filtering the Dataset and defining variables

#Filtering through crimes commited withith Rockville and through at least 6-10 different crime types
crimesrv <- mococrimes |>
  filter(City == "ROCKVILLE") |>
  filter(`Crime Name2` %in% c("Motor Vehicle Theft","Shoplifting","Simple Assault","Driving Under the Influence","Destrction/Damage/Vandalisim of Property","Drug/Narcotic Violations","Embezzlement","Tresspass of Real Property","All other Larceny","False Pretenses/Swindle/Confidence Game"))