Introduction

Police in Britain not only register every single crime they encounter, and include coordinates, but also distribute their data free on the web. For this project, data downloaded from all forces for Feburary 2022 for the whole Britain is used.

Data Preparation

The original dataset provided by the British Police is in csv format. The data scientist Fabio Veronesi made the data available on his site and analyses this data in this blog post.

dat <- read.csv("C:/Users/alexa/OneDrive/Desktop/STA 4233/2022-02/2022-02-metropolitan-street.csv")

Here is the structure of the dataset:

str(dat)
## 'data.frame':    80278 obs. of  12 variables:
##  $ Crime.ID             : chr  "86dcb4e75aee5e4f85faba482ae99f4b45d5ee7f694464482fbb4d2538457a71" "a8a306e3f41d1ef9b5601f0ee3f31b9bbfdbe41a64e3dc35eceb9e3360c9a373" "ea3405ba86a84efdc8c67421ec725550e88f31be484be36d6e67b9db4d83a110" "70b5893bdb519eb2613e3bb932f9b7a9a3462a76e9d6dff36e3e65e64653f3a1" ...
##  $ Month                : chr  "2022-02" "2022-02" "2022-02" "2022-02" ...
##  $ Reported.by          : chr  "Metropolitan Police Service" "Metropolitan Police Service" "Metropolitan Police Service" "Metropolitan Police Service" ...
##  $ Falls.within         : chr  "Metropolitan Police Service" "Metropolitan Police Service" "Metropolitan Police Service" "Metropolitan Police Service" ...
##  $ Longitude            : num  0.882 0.875 -0.972 -0.805 0.137 ...
##  $ Latitude             : num  51.2 51.2 52 51.8 51.6 ...
##  $ Location             : chr  "On or near Goat Lees Lane" "On or near Hardinge Road" "On or near Jarman Close" "On or near Rainborough Gardens" ...
##  $ LSOA.code            : chr  "E01032810" "E01024021" "E01017644" "E01017662" ...
##  $ LSOA.name            : chr  "Ashford 001F" "Ashford 004G" "Aylesbury Vale 002A" "Aylesbury Vale 015C" ...
##  $ Crime.type           : chr  "Violence and sexual offences" "Violence and sexual offences" "Theft from the person" "Violence and sexual offences" ...
##  $ Last.outcome.category: chr  "Under investigation" "Under investigation" "Investigation complete; no suspect identified" "Under investigation" ...
##  $ Context              : logi  NA NA NA NA NA NA ...

This dataset provides a series of useful information regarding the crime: its locations (longitude and latitude in degrees), the address (if available), the type of crime and the court outcome (if available). For this project, only the coordinates and the type of crime are used.

For some incidents the coordinates are not provided, and are removed from the data:

dat <- dat[!is.na(dat$Longitude)&!is.na(dat$Latitude),]

Mapping Clusters

Since there are so many points on a map that it doesn’t make sense to plot every marker. So, plots of clusters of markers with addMarkers(clusterOptions = markerClusterOptions()) are used. You can zoom in to each cluster, the clusters will separate until you can see the individual markers. The Crime Type is added as a popup for each marker. Click on any blue marker to determine what crime was committed.

library(leaflet)
## Warning: package 'leaflet' was built under R version 4.1.3
dat %>% 
  leaflet() %>% 
  addTiles() %>% 
  addMarkers(popup=dat$Crime.type , clusterOptions=markerClusterOptions())
## Assuming "Longitude" and "Latitude" are longitude and latitude, respectively

Conclusion

In this project open crime data was displayed using Leaflet, one of the most popular Javascript libraries for creating interactive maps. However, in only a few lines of code, the leaflet R package allowed the creation of my own leaflet map without needing to know any Javascript!