knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" ) library(dplyr)
ukmap provides a wrapper around the ONS (Offce for National Statistics) API for UK geospatial data.
ukmap is currently in the early stages of development, you can install it from GitHub with:
# install.packages("devtools") devtools::install_github("piersyork/ukmap")
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.