Download and Import the Crime dataset
First, I downloaded the estimated_crimes_1979_2022.csv from the FBI Crime Data Explorer at https://cde.ucr.cjis.gov/LATEST/webapp/#/pages/downloads#additionalDocuments. This dataset contains the estimated number of violent crimes in the United States from 1979 to 2022.
I then imported the file using the read.csv function and used the glimpse() command to show the variables in the dataset.
## Rows: 2,284
## Columns: 15
## $ year <int> 1979, 1979, 1979, 1979, 1979, 1979, 1979, 1979, 19…
## $ state_abbr <chr> "", "AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC"…
## $ state_name <chr> "", "Alaska", "Alabama", "Arkansas", "Arizona", "C…
## $ population <int> 220099000, 406000, 3769000, 2180000, 2450000, 2269…
## $ violent_crime <int> 1208030, 1994, 15578, 7984, 14528, 184087, 14472, …
## $ homicide <int> 21460, 54, 496, 198, 219, 2952, 161, 131, 180, 33,…
## $ rape_legacy <int> 76390, 292, 1037, 595, 1120, 12239, 1472, 752, 489…
## $ rape_revised <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
## $ robbery <int> 480700, 445, 4127, 1626, 4305, 75767, 4353, 6021, …
## $ aggravated_assault <int> 629480, 1203, 9918, 5565, 8884, 93129, 8486, 5998,…
## $ property_crime <int> 11041500, 23193, 144372, 70949, 177977, 1511021, 1…
## $ burglary <int> 3327700, 5616, 48517, 21457, 48916, 496310, 49741,…
## $ larceny <int> 6601000, 15076, 83791, 45267, 116976, 847148, 1178…
## $ motor_vehicle_theft <int> 1112800, 2501, 12064, 4225, 12085, 167563, 13345, …
## $ caveats <chr> "", "", "", "", "", "", "", "", "", "", "", "", ""…
Data Reorganization and Joining
I then filtered the data, so I could create a choropleth with data from only 2022, which is the most recent year in the dataset. There was summary information in the dataset that had a state name of “United States Total” so I removed that data to make joining easier. I then renamed the column state_name to region and changed the case to lower so it could be joined with the state_data dataset.
I then joined the crime_2022 dataset with the state_data dataset using the region variable. Once that was joined, I updated the region back to title case so it would look better in the leaflet choropleth map.
Create Choropleth Maps showing Estimated Violent Crime Rates by State in 2022
I then created a choropleth map using ggplot. I used green for lower crime states and red for higher crime states because, typically in our society red is associated with danger and green with safety.
I wanted to make the map interactive and easier to understand at the state level, so I recreated it using leaflet.
Initially, the colors were red for lowest crime and green for highest, however based on the reasoning listed previously, I reversed the color scheme.