knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
library(dplyr)

ukmap

ukmap provides a wrapper around the ONS (Offce for National Statistics) API for UK geospatial data.

Installation

ukmap is currently in the early stages of development, you can install it from GitHub with:

# install.packages("devtools")
devtools::install_github("piersyork/ukmap")

Example

The core function of ukmap is uk_map() which takes an area code or vector of area codes and returns the spatial features map data for the area. To get the area codes for different area types you can use uk_codes(), which takes an area type code or vector of codes and returns all the area codes for that area type.

library(ukmap)

# get map data for london boroughs
london <- uk_codes("E09") |> 
  uk_map()

# use the tmap package to easily see what the map data looks like
tmap::qtm(london)

You are able to pass the area code column of a dataframe to uk_map() to make the process of getting map data easier.

london_unemployment <- uk_unemployment |> 
  filter(grepl("^E09", area_code))   # area codes that start E09 are London boroughs

map_data <- uk_map(london_unemployment$area_code) # get the boundaries for the area codes in london_unemployment

map_data |> 
  left_join(london_unemployment, by = "area_code") |> # join london_unemployment to map_data
  tmap::qtm(fill = "unemployment_rate")

TO-DO



piersyork/ukmap documentation built on June 16, 2022, 3:35 a.m.