1 Introduction

In this computer assessment you will build a single Shiny app containing two interactive visualisations of Northern Ireland census geography data. The content assessed is:

Total marks: 10

2 Creating the deliverable

2.1 Packages

Ensure the following packages are installed, installing any that are missing:

install.packages(c("shiny", "ggplot2", "dplyr", "sf"))

Load them at the top of your app.R:

library(shiny)
library(ggplot2)
library(dplyr)
library(sf)

2.2 Creating app.R

In RStudio, go to File → New File → Shiny Web App. Set the app name to computer-assessment and choose Single File (app.R). RStudio will create a new folder called computer-assessment/ in your working directory containing app.R. All your work for this assessment goes inside that app.R.

The two visualisations required by Questions 1 and 2 must both live in this single app, sharing the same input control. Place the two plots side by side using fluidRow() and column() (each column with width = 6).

3 Question 1: Geospatial map (6 marks)

Download the Northern Ireland Super Data Zone (SDZ) boundaries from NISRA at https://www.nisra.gov.uk/publications/super-data-zone-boundaries-gis-format (choose the ESRI Shapefile option). Extract the downloaded zip file directly into your computer-assessment/ folder, so that the path computer-assessment/geography-sdz2021-esri-shapefile/SDZ2021.shp exists.

At the top of app.R, above the ui and server definitions, add the following line to load the data once when the app starts:

ni <- read_sf("geography-sdz2021-esri-shapefile/SDZ2021.shp")

The object ni is a simple feature collection with 850 rows (one per Super Data Zone) and the following columns relevant to this assessment:

Column Description
SDZ2021_cd SDZ code
SDZ2021_nm SDZ name
LGD2014_nm Local Government District name (11 districts)
Area_ha Area in hectares
Perim_km Perimeter in kilometres

Add a selectInput to the UI that lets the user choose one of the 11 Local Government Districts from LGD2014_nm. Use the unique values of ni$LGD2014_nm as the choices.

In the server, create a renderPlot() that produces a map with two layers:

  1. A base layer showing all 850 Super Data Zones in grey boundary, using geom_sf(data = ni).
  2. A top layer showing only the Super Data Zones belonging to the district selected by the user, with the fill aesthetic according to the variable Perim_km and the boundaries not shown, meaning that you will have aes(fill = Perim_km) and colour = NA somewhere in the code.

For reference, if the selected Local Government District is “Belfast”, your map should look like this:

4 Question 2: Scatterplot (4 marks)

Using the same selectInput from Question 1, add a second renderPlot() to the server that produces a scatterplot of Area_ha (y-axis) against Perim_km (x-axis) for the Super Data Zones belonging to the selected Local Government District only.

For reference, if the selected Local Government District is “Belfast”, your map should look like this:

5 Question 3: Labels and titles (0 marks)

Add meaningful labels and titles to both plots. Although this question carries no marks, clear labels are expected in professional data visualisation. Use labs() to set x, y, fill and title for each plot. The title could, for example, display the currently selected district name.