The purpose of this R Markdown is to illustrate the spatial distribution of stop and searches of 10-17 year olds in Wandsworth. The open data used in this analysis comes from data.police.uk and the London Datastore.
Dr Matt Ashby from the UCL describes stop and search as a:
“legal power that allows police officers to search people to find out if they are carrying prohibited items such as drugs, weapons or stolen goods. Stop and search means officers can confirm if a person is or is not in possession of contraband without arresting them and taking them to a police station, but it is also a source of tension between police and communities. A review by the College of Policing (Quinton, Tiratelli and Bradford, 2020) found little relationship between how many searches police do and how much crime occurs, but police insist stop and search helps them fight crime.(Ashby, 2020)”
Stop and search is overwhelmingly an issue affecting young people (LondonAssembly, 2017).
data.police.uk is a resource for open data about crime and policing in England, Wales and Northern Ireland. ukpolice is an R package that facilitates the retrieving of data from the UK police database. The following code draws data from the Metropolitan Police Service on stop and searches that took place in June, July and August 2021.
To protect the location privacy of victims, these data are obfuscated using geomasking techniques to reduce their spatial accuracy.
The following is a list of packages required for this analysis.
library(broom)
library(ggplot2)
library(ggmap)
library(ggthemes)
library(leaflet)
library(leaflet.extras)
library(magrittr)
library(mapproj)
library(raster)
library(RColorBrewer)
library(reshape2)
library(rgdal)
library(rgeos)
library(tidyverse)
library(sf)
library(sp)
library(stars)
library(viridis)
library(ukpolice)
The ukpolice R package can be used to download data from the UK Police public data API. Further documentation is available at https://data.police.uk/docs/. For the purposes of this analysis only data from June to August is downloaded.
# Download stop and search data for London for June to August 2021
london_ss_2021_Jun <- ukc_stop_search_force("metropolitan", date = "2021-06")
london_ss_2021_Jul <- ukc_stop_search_force("metropolitan", date = "2021-07")
london_ss_2021_Aug <- ukc_stop_search_force("metropolitan", date = "2021-08")
# Combine the three months of stop and search information into one set of data.
london_ss_2021 <- rbind(london_ss_2021_Jun,
london_ss_2021_Jul,
london_ss_2021_Aug)
This includes removing missing values and applying the correct projection to the points. The stop and search points are then plotted.
# Remove missing latitude and longitude
london_ss_2021 %<>% filter(!is.na(latitude) & !is.na(longitude))
# Convert to tbl_df
london_ss_2021 %<>% tbl_df()
#convert column 'longitude' from character to numeric
london_ss_2021$longitude <- as.numeric(london_ss_2021$longitude)
#convert column 'latitude' from character to numeric
london_ss_2021$latitude <- as.numeric(london_ss_2021$latitude)
# Define latitude and longitude as our coordinates
coordinates(london_ss_2021) <- ~ longitude + latitude
# Apply longitude and latitude projection using raster package
crs(london_ss_2021) <- "+proj=longlat +datum=WGS84 +no_defs"
# Plot the points
plot(london_ss_2021)
For the purposes of this analysis a map of Wandsworth is created.
Wandsworth <- subset(ldn.wgs84, NAME == "Wandsworth")
The next stage of the analysis is to identify which of the stop and searches of those in the 10-17 age group took place in Wandsoworth. This involves pinpointing the points that fall within the Wandsworth shapefile.
# Take subset of stop and searches for those in the 10-17 age group
Stop_Search <- london_ss_2021 %<>% subset(age_range %in% c("10-17"))
## query:
Stop_Search_xy <- Stop_Search@coords
Wandsworth_xy <- Wandsworth@polygons[[1]]@Polygons[[1]]@coords
test_points2 <- point.in.polygon(
Stop_Search_xy[,1], Stop_Search_xy[,2],
Wandsworth_xy[,1], Wandsworth_xy[,2])
Stop_Search_Wandsworth <- Stop_Search[which(test_points2 == T), ]
# Create a Dataframe
Stop_Search_Wandsworth_df <- as.data.frame(Stop_Search_Wandsworth)
# Plot Wandsworth
plot(Wandsworth, col = "grey80")
plot(Stop_Search_Wandsworth, pch = 20, add = T)
Map1 <- Stop_Search_Wandsworth_df %>%
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addHeatmap(lng=~as.numeric(Stop_Search_Wandsworth_df$longitude),
lat=~as.numeric(Stop_Search_Wandsworth_df$latitude),
radius = 8)
Map1
Police in Wandsworth stopped and searched 129 children and young people in the 10-17 age group in the three months from June to August 2021.
Stop and search is typically used in areas of higher deprivation or crime. Even at police force area level, there is significant variation in levels of stop and search, including areas where levels of stop and search are much more concentrated (‘Stop and search data and the effect of geographical differences’, 2021).
The following map plots the details of stops and searches in Wandsworth.
# Create lables for the Leaflet map
Stop_Search_Wandsworth_labels <- paste0(
"<strong>Outcome:</strong> ", Stop_Search_Wandsworth_df$outcome,"</br>",
"<strong>Street description:</strong> ", Stop_Search_Wandsworth_df$street_name, "</br>",
"<strong>Object of search:</strong> ", Stop_Search_Wandsworth_df$object_of_search
) %>% lapply(htmltools::HTML)
# Create the map
Map2 <- Stop_Search_Wandsworth_df %>%
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addCircleMarkers(lng = Stop_Search_Wandsworth_df$longitude,
lat = Stop_Search_Wandsworth_df$latitude,
popup = Stop_Search_Wandsworth_labels,
clusterOptions = markerClusterOptions())
Map2
The geographic distribution of stop and search in Wandsworth is different depending on the reason the stop and search was carried out. The following faceted map illustrates the geographic distribution of the four main types of search.
# Copy the spatial points data frame, renaming
Stop_Search_Wandsworth_spdf <- Stop_Search_Wandsworth
# Convert the spatial points data frame to tbl_df
Stop_Search_Wandsworth_df <- Stop_Search_Wandsworth_df %>% tbl_df()
# Create the theme for the map
theme_PR <- theme(
legend.position = "bottom",
panel.background = element_rect(fill = NA),
# panel.border = element_rect(fill = NA, color = "grey75"),
axis.ticks = element_line(color = "grey95", size = 0.3),
panel.grid.major = element_line(color = "grey95", size = 0.3),
panel.grid.minor = element_line(color = "grey95", size = 0.3),
legend.key = element_blank())
# Create the map
ggplot(data = Stop_Search_Wandsworth_df) +
geom_path(data = Wandsworth, aes(long, lat, group = group),
size = 0.3, color = "grey60") +
geom_point(aes(longitude, latitude, color = object_of_search, alpha = object_of_search),
size = 2) +
scale_color_brewer(palette="Set1") +
xlab("") + ylab("") +
ggtitle("Spatial distribution of stop and searches of 10-17 year olds \n by 'reason the stop and search was carried out'",
subtitle = "Wandsworth, 1 June to 31 August 2021") +
theme_PR +
facet_wrap(. ~ object_of_search) +
theme(legend.position = "none", axis.text = element_blank()) +
coord_map()
The ARE 212 provides a fantastic resource to teach users how to undertake a spatial anaysis in R https://edrub.in/ARE212/section12.html#spatial_data