Section 7.2 Burglaries in NYC
Like in Chapter 6, our data come from the Crime Open Database (CODE), a service that makes it convenient to use crime data from multiple US cities in research on crime. All the data in CODE are available to use for free as long as you acknowledge the source of the data. The package
crimedata was developed by Dr. Ashby to make it easier to read into R the data from this service. In the last chapter we provided the data in a csv format, but here we will actually make use of the package to show you how you might acquire such data yourself.
The key function in
crimedata is get_crime_data(). We will be using the crime data from New York City police and for 2010, and we want the data to be in sf format. We will also filter the data to only include residential burglaries in Brooklyn.
# Large dataset, so it will take a while
nyc_burg <- get_crime_data(
cities = "New York", #specifies the city for which you want the data
years = 2010, #reads the appropriate year of data
type = "extended", #select extended (a fuller set of fields)
output = "sf") %>% #return a sf object (vs tibble)
filter(offense_type == "residential burglary/breaking & entering" &
nyc_boro_nm == "MANHATTAN")
Additionally, we will need a geometry of borough boundaries. We have downloaded this from the NYC open data portal, and it is supplied with the data included with this book. The file is
manhattan.geojson.
manhattan <- st_read("data/manhattan.geojson") %>%
filter(BoroName == "Manhattan") # select only Manhattan
Now that we have all our data, let’s plot to see how they look.
ggplot() +
geom_sf(data = manhattan) + # boundary data
geom_sf(data = nyc_burg, size = 0.5) + # crime locations as points
theme_void()

In the point pattern analysis literature each point is often referred to as an event and these events can have marks, attributes or characteristics that are also encoded in the data. In our spatial object, one of these marks is the type of crime (although in this case it is of little interest since we have filtered on it). Others in this object include the date and time, location category, victim sex and race, etc.
