23  Network Visualisation

Interactive maps of entire UK air quality monitoring networks

Author

Jack Davison

Abstract
Using importMeta() provides a simple, tabular data set of monitoring stations. This is useful if users have specific sites, pollutants or local authorities in mind, but it is difficult to get a feel for the geographic distribution of a monitoring network. This section details how networkMap() can allow readers to visualise and explore any UK monitoring network.

23.1 Introduction

openair makes it easy to access any of the UK’s air quality monitoring networks. The following networks are available:

  • The Automatic Urban and Rural Network (AURN), the UK’s national network.

  • The devolved UK networks; Air Quality England (AQE), Scotland (SAQN), Wales (WAQN) and Northern Ireland (NI).

  • Locally managed English networks operated by individual local authorities.

  • The Imperial College London (formerly Kings College London) network.

  • A simplified Europe-wide air quality network (although the saqgetr package better serves obtaining European AQ data).

Lets consider the metadata available for the AURN.

library(openair)
aurn_meta <- importMeta(source = "aurn", all = TRUE)
dplyr::glimpse(aurn_meta)
Rows: 2,770
Columns: 14
$ code            <chr> "ABD", "ABD", "ABD", "ABD", "ABD", "ABD", "ABD", "ABD"…
$ site            <chr> "Aberdeen", "Aberdeen", "Aberdeen", "Aberdeen", "Aberd…
$ site_type       <chr> "Urban Background", "Urban Background", "Urban Backgro…
$ latitude        <dbl> 57.15736, 57.15736, 57.15736, 57.15736, 57.15736, 57.1…
$ longitude       <dbl> -2.094278, -2.094278, -2.094278, -2.094278, -2.094278,…
$ variable        <chr> "O3", "NO", "NO2", "NOx", "SO2", "CO", "PM10", "NV10",…
$ Parameter_name  <chr> "Ozone", "Nitric oxide", "Nitrogen dioxide", "Nitrogen…
$ start_date      <dttm> 2003-08-01, 1999-09-18, 1999-09-18, 1999-09-18, 2001-…
$ end_date        <chr> "2021-09-20", "2021-09-20", "2021-09-20", "2021-09-20"…
$ ratified_to     <dttm> 2021-09-20, 2021-09-20, 2021-09-20, 2021-09-20, 2007-…
$ zone            <chr> "North East Scotland", "North East Scotland", "North E…
$ agglomeration   <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
$ local_authority <chr> "Aberdeen City", "Aberdeen City", "Aberdeen City", "Ab…
$ source          <chr> "aurn", "aurn", "aurn", "aurn", "aurn", "aurn", "aurn"…

This dataset has 2770 rows and 14 columns, which is a lot of information to explore in a tabular format. A more effective way to communicate this information could be a map, which can be created automatically using openairmaps.

23.2 The networkMap() function

Network visualisation is the simplest family of functions in openairmaps — in fact, it only has one member. networkMap() is a function which you can consider as an analogue to importMeta() from openair. Consider networkMap() as an analogue to importMeta() — it can map any of the sources that importMeta() can, using the same codes ("aurn", "saqn", "local", "kcl", etc.) to select sites. Figure 23.1 visualises the active AURN sites as of 2023-05-22.

library(openairmaps)
networkMap(source = "aurn")
Figure 23.1: An interactive map of the AURN monitoring network.

networkMap() is a quite simple function, with the following arguments for customisation:

  • source: Any number of the importMeta() sources — can be “aurn”, “saqn” (or “saqd”), “aqe”, “waqn”, “ni”, “local”, “kcl” or “europe”.

  • control: Any column of the equivalent importMeta() dataset, which is used to create a “layer control” menu to allow readers to filter for certain sites. The control option is quite opinionated, and selects an appropriate style of layer control depending on the column selected (e.g., pollutants are switched between, whereas multiple site types can be selected at once)

  • date: By default, networkMap() shows currently active monitoring sites. By specifying date, sites active at that date will be shown. This may be of interest if you want to explore the history of your chosen monitoring site. Dates can either be provided as a character string in the “YYYY-MM-DD” format, or alternatively as a single year (e.g., date = 2020) which will show sites still operational at the end of that year.

  • cluster: By default, markers are clustered together until users zoom in close. This default behaviour improves the appearance and performance of the HTML map widget. The cluster argument allows you to turn this feature off.1

  • provider: Any number of the leaflet providers (see leaflet::providers or the list in the openairmaps overview page).

Some of these arguments are demonstrated in Figure 23.2, which shows the AURN, AQE Network, and locally managed English networks.2 Pay particular attention to the layer control menu, which allows you to toggle different site types on and off.

networkMap(source = c("aurn", "aqe", "local"),
           control = "site_type")
Figure 23.2: Demonstrating more features of networkMap().

23.3 “Do It Yourself” Network Maps

If you are only interested in a few sites, you may wish to create your own, smaller network map. Currently, openairmaps only contains functionality to visualise entire networks, but it is relatively easy to create a map of your own using leaflet. While Figure 23.3 shows a network map of just sites in York, its associated code chunk can be used as a template for other small network maps. It uses the buildPopup() function from openairmaps which was written for use with the directional analysis mapping functions, so is described in greater detail on the next page.

library(leaflet)
library(dplyr)
library(stringr)

# import all Meta data for the AURN
aurn_meta <- importMeta("aurn", all = TRUE)

# prep data for leaflet
map_data <- 
  aurn_meta %>%
  # get sites in York
  filter(local_authority == "York") %>% 
  # build a popup
  buildPopup(
    latitude = "latitude",
    longitude = "longitude",
    cols = c("code", "site", "site_type", "zone", "local_authority"), 
    names = c("AURN Code" = "code", "Name" = "site", 
              "Site Type" = "site_type", 
              "Zone" = "zone", "LA" = "local_authority")
  ) %>%
  # get unique sites
  distinct(site, .keep_all = TRUE)

# create a basic leaflet map
leaflet(map_data) %>%
  addTiles() %>%
  addMarkers(popup = ~popup)
Figure 23.3: Demonstrating more features of networkMap().

  1. This feature cannot be turned off when network = "europe" due to the number of markers creating performance issues.↩︎

  2. Note that networks can overlap — AQE sites can be part of the AURN. networkMap() uses the user-provided order as a hierarchy, so if “aurn” is listed first, an AURN & AQE site will be labelled as part of the AURN and its AURN code will be displayed↩︎