GitXplorerGitXplorer
n

ukpolice

public
36 stars
9 forks
11 issues

Commits

List of commits on branch master.
Unverified
96ec0e575daa431fbf5a746ba102b3fdd82c06d2

adds glue and general doco fixes

nnjtierney committed 6 years ago
Unverified
bf5416bb08419c75ec85f7c3b3fc75273fb0b5de

Fixes typo in the label of the graphic to use the correct date. close #21

nnjtierney committed 6 years ago
Unverified
6733620e13a54a23ee7fd9be32f0da1f2a18e9b3

fixed up text formatting and other minor formatting changes suggested from good practice

nnjtierney committed 7 years ago
Unverified
e6ad3ab4ab89bb7f6d02a46045be0aecbe59a35f

add lifecycle badge

nnjtierney committed 7 years ago
Unverified
fa9b26c808c42b4fb8dadac950520ccbe0da8924

update docs to include hex

nnjtierney committed 7 years ago
Unverified
20316dbd79d22ce6818cd401f4a0e7f8ef702db5

update README.md

nnjtierney committed 7 years ago

README

The README file for this repository.

ukpolice

AppVeyor Build StatusTravis-CI Build StatusCoverage Status lifecycle

ukpolice is an R package that facilitates retrieving data from the UK police database.. The data provided by the API contains public sector information licensed under the Open Government Licence v3.0.

Installation

Install from GitHub

#install.packages("remotes")
remotes::install_github("njtierney/ukpolice")

Get the crime data with ukp_crime

ukp_crime() draws crimes from within a one mile radius of the location. When no date is specified, it uses the latest month available, which can be found using ukp_last_update().

library(ukpolice)

crime_data <- ukp_crime(lat = 52.629729, lng = -1.131592)
#> No encoding supplied: defaulting to UTF-8.

head(crime_data)
#> # A tibble: 6 x 12
#>   category persistent_id date    lat  long street_id street_name context
#>   <chr>    <chr>         <chr> <dbl> <dbl> <chr>     <chr>       <chr>  
#> 1 anti-so… ""            2018…  52.6 -1.13 883389    On or near… ""     
#> 2 anti-so… ""            2018…  52.6 -1.13 883356    On or near… ""     
#> 3 anti-so… ""            2018…  52.6 -1.14 883430    On or near… ""     
#> 4 anti-so… ""            2018…  52.6 -1.13 883378    On or near… ""     
#> 5 anti-so… ""            2018…  52.6 -1.12 883201    On or near… ""     
#> 6 anti-so… ""            2018…  52.6 -1.14 883426    On or near… ""     
#> # … with 4 more variables: id <chr>, location_type <chr>,
#> #   location_subtype <chr>, outcome_status <chr>

ukp_last_update()
#> No encoding supplied: defaulting to UTF-8.
#> [1] "2018-11"

Specify a month and year for data

When date is specified, it must be in the format “YYYY-MM”. Currently ukp_crime() only allows for searching of that current month.

crime_data_date <- ukp_crime(lat = 52.629729, 
                             lng = -1.131592,
                             date = "2016-03")
#> No encoding supplied: defaulting to UTF-8.

head(crime_data_date)
#> # A tibble: 6 x 12
#>   category persistent_id date    lat  long street_id street_name context
#>   <chr>    <chr>         <chr> <dbl> <dbl> <chr>     <chr>       <chr>  
#> 1 anti-so… ""            2016…  52.6 -1.13 883288    On or near… ""     
#> 2 anti-so… ""            2016…  52.6 -1.13 883321    On or near… ""     
#> 3 anti-so… ""            2016…  52.6 -1.13 883362    On or near… ""     
#> 4 anti-so… ""            2016…  52.6 -1.13 883388    On or near… ""     
#> 5 anti-so… ""            2016…  52.6 -1.13 883359    On or near… ""     
#> 6 anti-so… ""            2016…  52.6 -1.11 883060    On or near… ""     
#> # … with 4 more variables: id <chr>, location_type <chr>,
#> #   location_subtype <chr>, outcome_status <chr>

This is still a little buggy at the moment as it returns blank columns for variables like persistent_id and context, location_subtype, and outcome_status. This issue is currently logged at issue #11.

Example usage

Explore the number of crime types

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)

crime_data <- ukp_crime(lat = 52.629729, lng = -1.131592)
#> No encoding supplied: defaulting to UTF-8.

crime_data %>%
  count(category) %>%
  ggplot(aes(x = reorder(category, n),
             y = n)) + 
  geom_col() + 
  labs(x = "Crime Type",
       y = "Number of Crimes",
       title = paste0("Crimes commited in ",crime_data$date[1])) +
  coord_flip() +
  theme_minimal()

Using leaflet

You can add a popup that displays the crime type using the popup argument in leaflet.

library(leaflet)
crime_data <- ukp_crime(lat = 52.629729, lng = -1.131592)
#> No encoding supplied: defaulting to UTF-8.
crime_data %>%
  leaflet() %>%
  addTiles() %>%
  addCircleMarkers(popup = ~category)
#> Assuming "long" and "lat" are longitude and latitude, respectively

Other use of ukpolice

ukpolice does other things! At the moment other features include:

  • Get crime within a polygon with ukp_crime_poly()
  • Retrieve a list of neighbourhoods for a police force with ukp_neighbourhood()

To see these examples, read the vignette “Getting Started with ukpolice”.

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Thanks

hex sticker police logo “Police” created by Yu luck from the Noun Project, hex sticker made with hexSticker package