https://github.com/nacnudus/nzpullover
New Zealand road policing data
https://github.com/nacnudus/nzpullover
dataset government-data new-zealand police r roads
Last synced: 2 months ago
JSON representation
New Zealand road policing data
- Host: GitHub
- URL: https://github.com/nacnudus/nzpullover
- Owner: nacnudus
- Created: 2017-01-27T23:10:50.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-10-08T09:07:32.000Z (over 6 years ago)
- Last Synced: 2025-02-05T21:42:09.336Z (3 months ago)
- Topics: dataset, government-data, new-zealand, police, r, roads
- Language: R
- Homepage: https://nacnudus.github.io/nzpullover/
- Size: 14.7 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
---
output: github_document
---```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "figures/README-"
)
```# nzpullover
[](https://travis-ci.org/nacnudus/nzpullover)
[](https://ci.appveyor.com/project/nacnudus/nzpullover)
[](https://cran.r-project.org/web/packages/nzpullover/index.html)
[](https://www.r-pkg.org/pkg/nzpullover)The nzpullover package makes available road policing data from the New Zealand
Police in a convenient 'tidy' form. Offence categories include speed, alcohol,
red light, restraints (seatbelts), mobile phone, fleeing drivers, and speeding
police vehicles.The original data published by the New Zealand Police is available as a
spreadsheet here:
[http://www.police.govt.nz/about-us/publication/road-policing-driver-offence-data-january-2009-june-2018](http://www.police.govt.nz/sites/default/files/publications/road-policing-driver-offence-data-1jan2009-30june2018.xlsx).
Please note that this R package is not associated with the New Zealand Police.The spreadsheet data has been made tidy by using the
[tidyxl](https://github.com/nacnudus/tidyxl) and
[unpivotr](https://github.com/nacnudus/unpivotr) packages. See the scripts in
[/data-raw](https://github.com/nacnudus/nzpullover/tree/master/data-raw).
Zipped csv files are available in
[/inst/extdata](https://github.com/nacnudus/nzpullover/tree/master/inst/extdata).The New Zealand Police refresh the data approximately quarterly. If this
package lags behind, then please open an issue
[https://github.com/nacnudus/nzpullover/issues](https://github.com/nacnudus/nzpullover/issues).
The CRAN version will be updated annually.## Installation
You can install nzpullover from github with:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("nacnudus/nzpullover")
```## Example
Scroll to the bottom for lots more graphs.
```{r example, echo = FALSE, message = FALSE, fig.width = 9, fig.show = "hold"}
library(nzpullover)
library(tidyverse)
library(forcats)plotdata <-
excess %>%
mutate(series = fct_recode(series,
`Officer-issued` = "Officer-issued excess speed band",
`Camera-issued` = "Camera-issued excess speed band")) %>%
filter(series %in% c("Officer-issued",
"Camera-issued")) %>%
group_by(series, month, speed) %>%
summarise(value = sum(value)) %>%
group_by(series, month) %>%
mutate(prop = value / sum(value),
cumprop = cumsum(prop))plotdata %>%
ggplot(aes(speed, value, colour = month)) +
geom_point(shape = "-", size = 20) +
scale_colour_continuous(name = "", trans = "date") +
scale_y_continuous(labels = scales::comma) +
facet_wrap(~series, nrow = 1) +
ggtitle("New Zealand summer speed limit infringements/offences",
subtitle = "Frequency in each speed band") +
xlab("Speed band (km/h over the limit)") +
ylab("Frequency")plotdata %>%
ggplot(aes(speed, cumprop, colour = month)) +
geom_point(shape = "-", size = 20) +
scale_colour_continuous(name = "", trans = "date") +
scale_y_continuous(labels = scales::percent) +
facet_wrap(~series, nrow = 1) +
ggtitle("New Zealand summer speed limit infringements/offences",
subtitle = "Cumulative proportion in each speed band") +
xlab("Speed band (km/h over the limit)") +
ylab("Cumulative proportion")
``````{r, echo = TRUE}
glimpse(driving_offences)
glimpse(static_camera)
glimpse(excess)
glimpse(fleeing_area)
glimpse(fleeing_district)
glimpse(police_speeding)
glimpse(police_speeding_band)
```## Other New Zealand datasets by the same author:
* [nzlifetables](https://github.com/nacnudus/nzlifetables) -- cohort life
tables
* [nzcensus2013](https://github.com/nacnudus/nzcensus2013) -- summary statistics
from the 2013 New Zealand census
* [nzbabynames](https://github.com/nacnudus/nzbabynames) -- the top 100 baby
names annually since 1954, and annual birth statistics.## Lots more graphs
```{r, echo = FALSE, warning = FALSE}
library(tidyverse)
library(fs)
library(nzpullover)theme_set(theme_grey() + theme_minimal())
all_months <- tibble(month = seq(min(driving_offences$month),
max(driving_offences$month),
by = "month"))timeseries <- function(series) {
series_plot <-
driving_offences %>%
filter(series == rlang::UQ(series)) %>%
group_by(month) %>%
summarise(value = sum(value)) %>%
right_join(all_months, by = "month") %>%
ggplot(aes(month, value)) +
geom_line() +
geom_point() +
scale_y_continuous(limits = c(0, NA), labels = scales::comma) +
xlab("") +
ylab("") +
ggtitle(str_wrap(series))
print(series_plot)
}driving_offences %>%
distinct(series) %>%
pull(series) %>%
walk(timeseries)
```