subtitle: "Local Authority and Middle-layer Super Output Area exmaples"
author: "Tom Rushby"
date: "25/06/2021"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r requiredPackages}
library(curl)
library(sf)
library(tidyverse)
library(ggplot2)
```
## Introduction
This example follows an example (and re-uses code) by [@VictimOfMaths](https://github.com/VictimOfMaths/Maps/blob/master/WFHCartogram.R) using hex-map data from [House of Commons Library](https://github.com/houseofcommonslibrary/uk-hex-cartograms-noncontiguous/) by [@carlbaker](https://twitter.com/carlbaker).
The first example we will look at is plotting a non-contiguous hex cartogram of Local Authority areas.
The file downloaded is a GeoPackage (.gpkg) file, an SQLite Database container (see http://www.geopackage.org/guidance/getting-started.html for more info.). We can examine the layers contained using the `st_layers()` command from the sf package.
```{r examineGeoLayers}
st_layers(ltla)
```
Next we extract the layers we want using the `st_read` command. [Alternative methods](https://olalladiaz.net/blog/2018/11/02/working-with-gpkg-r/) are available.
```{r extractGeoLayers}
Background <- st_read(ltla, layer="7 Background")
Areas <- st_read(ltla, layer="4 LTLA-2019")
Groups <- st_read(ltla, layer="2 Groups")
Group_labels <- st_read(ltla, layer="1 Group labels") %>%
mutate(just=if_else(LabelPosit=="Left", 0, 1))
```
And finally we can make a plot ... note the `Groups` geometry provides County-level grouping of local authorities and an outline (appears bold in the plot below). `Areas` provides the local authority outlines.
msoa_la_outlines <- st_read(msoa, layer="3 Local authority outlines (2019)")
msoa_data <- st_read(msoa, layer="4 MSOA hex")
msoa_groups <- st_read(msoa, layer="2 Groups")
msoa_group_labels <- st_read(msoa, layer="1 Group labels") %>%
mutate(just=if_else(LabelPosit=="Left", 0, 1))
```
As with the local authority example, `msoa_groups` and `msoa_la_outlines` geometries provide County- and Local Authority-level grouping/outlines (black in the plot below). `msoa_data` provides the MSOA outlines (in blue).