Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

R package for accessing data from the Crime Open Database

License

NotificationsYou must be signed in to change notification settings

mpjashby/crimedata

Repository files navigation

CRAN statusLifecycle: stable

The goal of crimedata is to access police-recorded crime data from largeUS cities using theCrime Open Database (CODE),a service that provides these data in a convenient format for analysis.All the data are available to use for free as long as you acknowledgethe source of the data.

The functionget_crime_data() returns atidy datatibble orsimple features(SF) object of crime data witheach row representing a single crime. The data provided for each offenseincludes the offense type, approximate offense location and date/time.More fields are available for some records, depending on what data havebeen released by each city. For most cities, data are available from2010 onward, with some available back to 2007. Uselist_crime_data()to see which years are available for which cities.

More detail about what data are available, how they were constructed andthe meanings of the different categories can be found on theCODEproject website. Further detail is available inthe paperStudying Crime and Place with the Crime OpenDatabase.

Installation

You can install the crimedata package with:

install.packages("crimedata")

You can install the latest development version of the crimedata packagefrom GitHub with:

# install.packages("remotes")remotes::install_github("mpjashby/crimedata")

Examples

Data can be downloaded by year and by city. By default (i.e. if noarguments are specified) a 1% sample of data for all cities for the mostrecent available year is returned.

library(crimedata)crime_data<- get_crime_data()

The data are in a tidy format, so can be quickly manipulated usingdplyr verbs. For example, toanalyze two years of personal robberies in Chicago and Detroit, you canrun:

suppressPackageStartupMessages(library(tidyverse))personal_robberies<- get_crime_data(years=2009:2010,cities= c("Chicago","Detroit"),type="core",quiet=TRUE) %>%   filter(offense_type=="personal robbery")

You can alternatively get asimple features(SF) point objectwith the correct co-ordinates and co-ordinate reference system (CRS)specified by setting the argumentoutput = "sf". This can be used, forexample, to quickly plot the data.

suppressPackageStartupMessages(library(lubridate))get_crime_data(cities="Fort Worth",years=2014:2017,type="core",quiet=TRUE,output="sf") %>%   filter(offense_group=="homicide offenses") %>%   mutate(offense_year= year(date_single)) %>%   ggplot()+   geom_sf()+  facet_wrap(vars(offense_year),nrow=1)#> Warning: Unknown columns: `location_type`
plot of chunk crimedata_sf_example

plot of chunk crimedata_sf_example

Included data

The package includes two datasets.homicides15 contains records of1,922 recorded homicides in nine US cities in 2015.nycvehicletheftscontains records of 35,746 thefts of motor vehicles in New York Cityfrom 2014 to 2017. These may be particularly useful for teachingpurposes.


[8]ページ先頭

©2009-2025 Movatter.jp