Created
June 27, 2017 13:37
-
-
Save rcatlord/e3757c6593d18eb713dee96403938e91 to your computer and use it in GitHub Desktop.
Using the data.police.uk API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(jsonlite) | |
# df <- jsonlite::fromJSON(txt="https://data.police.uk/api/crimes-street/all-crime?lat=53.444853&lng=-2.278289&date=2017-02") | |
df <- jsonlite::fromJSON(txt="https://data.police.uk/api/crimes-street/all-crime?poly=52.268,0.543:52.794,0.238:52.130,0.478&date=2017-02") | |
df$location$longitude <- as.numeric(as.character(df$location$longitude)) | |
df$location$latitude <- as.numeric(as.character(df$location$latitude)) | |
library(tidyverse) | |
df %>% | |
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 April 2015-04 ", df$date[1])) + | |
coord_flip() + | |
theme_minimal() | |
library(leaflet) | |
leaflet(data = df) %>% | |
addProviderTiles(providers$CartoDB.Positron) %>% | |
addMarkers(~location$longitude,~location$latitude, clusterOptions = markerClusterOptions(),popup = ~category) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment