Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/njtierney/ukpolice

:uk: :police_car: R package to pull police data from the uk police data repository :police_car: :uk:
https://github.com/njtierney/ukpolice

Last synced: 3 months ago
JSON representation

:uk: :police_car: R package to pull police data from the uk police data repository :police_car: :uk:

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r setup, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
```

# ukpolice
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/njtierney/ukpolice?branch=master&svg=true)](https://ci.appveyor.com/project/njtierney/ukpolice)[![Travis-CI Build Status](https://travis-ci.org/njtierney/ukpolice.svg?branch=master)](https://travis-ci.org/njtierney/ukpolice)[![Coverage Status](https://img.shields.io/codecov/c/github/njtierney/ukpolice/master.svg)](https://codecov.io/github/njtierney/ukpolice?branch=master) [![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)

ukpolice is an R package that facilitates retrieving data from the [UK police database.](https://data.police.uk/). The data provided by the API contains public sector information licensed under the [Open Government Licence v3.0.](http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/)

# Installation

Install from GitHub

```{r install, eval = FALSE}

#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()`.

```{r crime-example}
library(ukpolice)

crime_data <- ukp_crime(lat = 52.629729, lng = -1.131592)

head(crime_data)

ukp_last_update()

```

## 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.

```{r crime-data-date-example}

crime_data_date <- ukp_crime(lat = 52.629729,
lng = -1.131592,
date = "2016-03")

head(crime_data_date)

```

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](https://github.com/njtierney/ukpolice/issues/11).

# Example usage

## Explore the number of crime types

```{r count-example}

library(dplyr)
library(ggplot2)

crime_data <- ukp_crime(lat = 52.629729, lng = -1.131592)

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.

```{r leaflet-example-popup}
library(leaflet)
crime_data <- ukp_crime(lat = 52.629729, lng = -1.131592)
crime_data %>%
leaflet() %>%
addTiles() %>%
addCircleMarkers(popup = ~category)
```

# 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".

ukpolice also has functions for retrieving the stop and search data:

- `ukp_stop_search()`
- `ukp_stop_search_poly()`

## Code of Conduct

Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). 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](https://github.com/GuangchuangYu/hexSticker) package_