For When There's No Netflix...

In the airport, my favorite past time is watching whatever show I’ve been binging on Netflix. This time it’s Criminal Minds. However, in my rush to pack, I forgot headphones. So I figured I’d scratch that crime-obsessed itch by investigating Matthew Ashby’s {crimedata} package in R for y’all…

{crimedata} pulls from the Crime Open Database, allowing R users to conveniently explore and analyze crime data from major US cities.

{crimedata}, like {chorrrds} from last week’s tutorial, can be downloaded straight from the command line in R.

devtools::install_github("mpjashby/crimedata") 

Your next step is to prepare your newly downloaded {crimedata} package for use:

library(crimedata)

crime_data <- get_crime_data()

The above command will download a list of the URLs you need for comprehensive crime data analysis. After your URLs are downloaded in tidy format, you can easily plot crime location data across several years for any given city. I tried New Orleans first, but the data did not show, so I tried my original home city New York using this command:

get_crime_data(
  cities = "Fort Worth", 
  years = 2014:2017, 
  type = "core",
  output = "sf"
) %>% 
  filter(offense_group == "homicide offenses") %>% 
  mutate(offense_year = year(date_single)) %>% 
  ggplot() + 
  geom_sf() +
  facet_wrap(vars(offense_year))

The resulting plot, shown below, showed some interesting data:

Screen Shot 2021-06-14 at 3.03.48 PM.png

It seems that the locations of the crimes in New York from 2014-2017 as well as the amount of crime has stayed more or less the same. What happens when we increase the time span? Spoiler alert: not much…

Screen Shot 2021-06-14 at 3.14.12 PM.png

I wonder if this pattern is consistent across other cities, especially in a smaller city such as Fort Worth, TX:

Screen Shot 2021-06-14 at 3.21.39 PM.png

As I suspected, there’s more variation in Fort Worth’s amount of crime and locations than shown in New York’s data.

Want to go even deeper?

You can access the homicides15 dataset that’s part of the {crimedata} package and store it as your own variable: It’s this simple:

homicides <- homicides15 

Now you can play with the data, shown below, using any packages and commands you’ve learned in your other studies.


Like what you read?

Explore more exciting tutorials across programming languages by clicking below!

Danielle Oberdier