Coder Social home page Coder Social logo

ukpolice's Introduction

ukpolice

License: MIT Travis build status AppVeyor build status Coverage status CRAN_Status_Badge GitHub tag DOI R build status

The ukpolice package downloads data from the UK Police public data API, the full docs of which are available at https://data.police.uk/docs/. Data is available on police forces, crimes, policing areas and stop-and-search.

ukpolice is on CRAN, which you can download using:

install.packages("ukpolice")

You can install the development version of ukpolice from github with:

# install.packages("devtools")
devtools::install_github("evanodell/ukpolice")

Data is available on police forces, crimes, policing areas and stop-and-search. All functions begin with ukc_.

The example below queries stop and searches by the Thames Valley Police in December 2018, and plots them by police-reported ethnic group.

library(ukpolice)
library(ggplot2)
library(dplyr)

tv_ss <- ukc_stop_search_force("thames-valley", date = "2020-07")

tv_ss2 <- tv_ss %>% 
  filter(!is.na(officer_defined_ethnicity) & outcome != "" ) %>%
  group_by(officer_defined_ethnicity, outcome) %>%
  summarise(n = n()) %>%
  mutate(perc = n/sum(n))

theme_set(theme_bw())

p1 <- ggplot(tv_ss2, aes(x = outcome, y = perc,
                         group = outcome, fill = outcome)) + 
  geom_col(position = "dodge") + 
  scale_y_continuous(labels = scales::percent,
                     breaks = seq(0.25, 0.8, by = 0.25)) + 
  scale_x_discrete(labels = scales::wrap_format(20)) + 
  theme(legend.position = "none",
        axis.text.x = element_text(size = 7, angle = 45, hjust = 1)) + 
  labs(x = "Outcome", 
       y = "Percentage of stop and searches resulting in outcome",
       title = "Stop and Search Outcomes by Police-Reported Ethnicity",
       subtitle = "Thames Valley Police Department, July 2020",
       caption = "(c) Evan Odell | CC-BY-SA") + 
  facet_wrap(~officer_defined_ethnicity)

p1

For more details, see the package vignette vignette and function documentation.

Meta

Please note that the ‘ukpolice’ project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

The UK Police API is operated by the UK Government’s Home Office. The ukpolice package is not affiliated with the Home Office. All data accessed through ukpolice is licenced with Open Government Licence v3.0.

Get citation information for ukpolice in R with citation(package = 'ukpolice'), or use the citation information below:

Odell E, Tierney N (2020). ukpolice: Download Data on UK Police and Crime. doi: 10.5281/zenodo.2619537, R package version 0.2.2, URL: https://github.com/evanodell/ukpolice.

A BibTeX entry for LaTeX users is:

  @Manual{,
    title = {{ukpolice}: Download Data on UK Police and Crime},
    author = {Evan Odell and Nicholas Tierney},
    year = {2020},
    note = {R package version 0.2.2},
    doi = {10.5281/zenodo.2619537},
    url = {https://github.com/evanodell/ukpolice},
  }

ukpolice's People

Contributors

evanodell avatar seabbs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ukpolice's Issues

Working around URL Error 503

Hi,

I've tried to query a large custom poly, but result with the following message. Please see code below:

# Create large custom area
poly_big <- data.frame(
  lat = c(51.508449,51.368342,51.423457,51.512925),
  lng = c(-0.378617,-0.454862,-0.098453,-0.114220)
)
df <- ukc_crime_poly(poly_big)

#Returns error
"Request returned error code: 503"

I suspect this is do with: "If a custom area contains more than 10,000 crimes, the API will return a 503 status code." from the API documentation.

I had an idea to try and replace the httr::GET withing ukpolice::ukc_get_data with httr::POST, see code below, but havent' had much success.

baseurl <- "https://data.police.uk/api/crimes-at-location?"


#Create string in correct format 
ukc_poly_paste <- function(data,lng,lat) {
  poly_paste <- paste(paste(data$lat, data$lng, sep = ","), collapse = ":")
  
  poly_paste
}
poly_string <- ukc_poly_paste(poly_big,"lng","lat")
date = "2020-01"

POST <- httr::POST(url = baseurl,
                   body = list(
                     poly = poly,
                     date = date
                   ))

# Returns URL Error code 404

My knowledge of httr::POST is relatively little, so apologies for any errors from lack of understanding.

Thanks
Ronan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.