This repository was archived by the owner on Jun 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathREADME.Rmd
117 lines (76 loc) · 3.78 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
```
# ukpolice <img src="man/figures/ukpolice-hex-small.png" align="right" />
[](https://ci.appveyor.com/project/njtierney/ukpolice)[](https://travis-ci.org/njtierney/ukpolice)[](https://codecov.io/github/njtierney/ukpolice?branch=master) [](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_