Introduction

For this assignment I decided to experiment with different methods of mapping regional data in the UK, as that is where I live and thus this may be useful for future exercises!

GADM maps + raster

Possibly the easiest solution, this involves using the raster package’s getData() function to source data from GADM. Data is can be retrieved at 4 different levels:
0. - UK
1. - England, Scotland, Wales, Northern Ireland
2. - ? County
3. - ? Borough Councils

Exploring the head of this data we can see the form that it takes and thus construct a suitable plot in leaflet. The level/resolution at which the data is downloaded will determine the black divisions of the map, but we can fill and label them by different levels using the arguments below.

Credit must go to Rachit Kinger for his solution on Stack Overflow that illustrated this method to me.

library(sp)
## Warning: package 'sp' was built under R version 4.0.2
library(raster)
## Warning: package 'raster' was built under R version 4.0.2
shapeData <- getData('GADM', country='GBR', level = 3) 
# Level 0 = UK
# Level 1 = England, Scotland, Wales, Northern Ireland
# Level 2 = County?
# Level 3 = Borough Councils?

head(shapeData, 3)
##       GID_0         NAME_0   GID_1  NAME_1 NL_NAME_1     GID_2
## 39483   GBR United Kingdom GBR.1_1 England      <NA> GBR.1.1_1
## 43788   GBR United Kingdom GBR.1_1 England      <NA> GBR.1.2_1
## 41927   GBR United Kingdom GBR.1_1 England      <NA> GBR.1.3_1
##                             NAME_2 NL_NAME_2       GID_3
## 39483                     Barnsley      <NA> GBR.1.1.1_1
## 43788 Bath and North East Somerset      <NA> GBR.1.2.1_1
## 41927                 Bedfordshire      <NA> GBR.1.3.1_1
##                             NAME_3 VARNAME_3 NL_NAME_3               TYPE_3
## 39483                     Barnsley      <NA>      <NA> Metropolitan borough
## 43788 Bath and North East Somerset      <NA>      <NA>    Unitary authority
## 41927                      Bedford      <NA>      <NA>    Unitary authority
##                  ENGTYPE_3 CC_3   HASC_3
## 39483 Metropolitan borough <NA> GB.BX.BX
## 43788    Unitary authority <NA> GB.BN.BN
## 41927    Unitary authority <NA> GB.FO.FO
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.0.2
pal <- colorFactor("Blues", shapeData$GID_1)
leaflet(shapeData) %>% 
  addPolygons(color = "black", weight = 1, smoothFactor = 0.5,
              opacity = 1.0, fillOpacity = 0.5,
              fillColor = ~pal(GID_1),
             label = shapeData$NAME_3)