Purpose

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.

Introduction

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).

Metropolitan Police Service (MPS) stop and search data

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.

Packages

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)

Gathering the data

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)

Data preparation

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)

London Local Authority GIS Shapefile

A London Local Authority GIS Shapefile is available from the government’s London Datastore website. https://data.london.gov.uk/dataset/statistical-gis-boundary-files-london The Shapefile is then formatted to ensure that the projection matches the projection used for the stop and search point data.

# read in the shapefile
ldn <- readOGR(dsn = ".", "London_Borough_Excluding_MHW")
## OGR data source with driver: ESRI Shapefile 
## Source: "/cloud/project", layer: "London_Borough_Excluding_MHW"
## with 33 features
## It has 7 fields
proj4string(ldn) <- CRS("+init=epsg:27700")
ldn.wgs84 <- spTransform(ldn, CRS("+init=epsg:4326"))
# Tidy the shapefile
ldn.wgs84_df <- tidy(ldn.wgs84)
ggplot(data = ldn.wgs84_df, aes(x = long, y = lat, group = group )) +
  geom_polygon(fill = "grey90") +
  geom_path(size = 0.3) + 
  xlab("Longitude") +
  ylab("Latitude") + 
  ggtitle("London Local Authorities") +
  theme_classic() + 
  coord_map()

Create a Wandsworth map

For the purposes of this analysis a map of Wandsworth is created.

Wandsworth <- subset(ldn.wgs84, NAME == "Wandsworth")

Stop and searches in Wandsworth of those in the of 10-17 age group

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)

The geographic distribution of recorded stop and search hot spots in Wandsworth of 10-17 year olds

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.

To explore the stop and search map, click on the hotspots to see more details

# 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 recorded stop and searches, by reason the stop and search was carried out, of 10-17 year olds in Wandsworth

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()

Resources

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

References

Ashby, M. (2020) ‘Stop and search in london july to september 2020’. Available at: https://discovery.ucl.ac.uk/id/eprint/10115766/1/2020-Q3.pdf.
LondonAssembly (2017) ‘Stop and search - police and crime committee’. Available at: https://www.london.gov.uk/about-us/londonassembly/meetings/documents/s26909/Research%20into%20Young%20Peoples%20Views%20of%20Stop%20and%20Search%20for%20Police%20and%20Crime%20Committee%20Investigation%20-.pdf.
Quinton, P., Tiratelli, M. and Bradford, B. (2020) ‘Does more stop and search mean less crime?’. Available at: https://whatworks.college.police.uk/Research/Documents/SS_and_crime_report.pdf.
‘Stop and search data and the effect of geographical differences’ (2021). Available at: https://www.gov.uk/government/publications/stop-and-search-data-and-the-effect-of-geographical-differences/stop-and-search-interpreting-and-describing-statistics.