Instructions

Create a web page using R Markdown that features a map created with Leaflet.

Host your webpage on either GitHub Pages, RPubs, or NeoCities.

Your webpage must contain the date that you created the document, and it must contain a map created with Leaflet. We would love to see you show off your creativity!

Review Criteria

The rubric contains the following two questions:

Does the web page feature a date and is this date less than two months before the date that you’re grading this assignment?

Does the web page feature an interactive map that appears to have been created with Leaflet?

Nitrogen Dioxide Concentrations by Location in the UK & NI

Nitrogen dioxide is a known byproduct from the combustion of fossil fuels. Short term exposure can lead to inflammation of the airways and lead to respiratory infections. Nitrogen dioxide can also cause changes to the environment by changing soil chemistry and biodiversity.

Using DEFRA’s Automatic Urban and Rural Network (AURN) for ambient air quality monitoring, average nitrogen dioxide values for 2022 for each monitoring station across the UK & NI were extracted. These values were plotted with the corresponding monitoring station location.

Load appropriate libraries

library(openair)
library(tidyverse)
library(leaflet)
library(htmltools)

First the sites which record nitrogen dioxide are extracted using the meta data:

#extract meta data for the AURN dataset
meta_data <- importMeta(source = "aurn", all = TRUE)
#find sites that record nitrogen dioxide data
selected_data <- meta_data %>%
    filter(variable == "NO2")
#produce list of sites recording nitrogen dioxide, sites are listed in lower case
selected_sites <- selected_data %>%
    select(code) %>%
    mutate_all(.funs = tolower)

Averaged data for 2022 is extracted from the AURN database:

#download data from the Automatic Urban and Rural Network (AURN) on the UK air        pollution website
data <- importAURN(site = selected_sites$code, year =2022, data_type = "annual", pollutant = "no2")

Filtered data is then stitched together with the site list created above containing the site locations of the monitoring stations:

filtered_data <- meta_data %>%
    filter(variable == "NO2") %>%
    right_join(data, "code") %>%
    select(date, no2, code, site.x, site_type, latitude, longitude, variable) %>%
    rename(site = site.x) 

The data is plotted using leaflet:

# a colour palette is generated with highest values in red and lowest values in green
pal <- colorNumeric(palette = "RdYlGn", domain = filtered_data$no2, reverse = TRUE)

# the filtered data with nitrogen dioxide concentrations and geographic location are plotted
# using leaflet
m = leaflet(as.data.frame(filtered_data)) %>% addTiles %>%  
    addCircleMarkers(weight = 1, stroke = TRUE, color = "Black", radius = ~10, fillOpacity = 0.8,fillColor = ~pal(no2), 
    popup = htmlEscape(paste(filtered_data$site, ",", filtered_data$no2, "ug/m3")))
m