Skip to content

Instantly share code, notes, and snippets.

@dakvid
Created November 6, 2021 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dakvid/f10a75cf490d065f9f8ed4dab5e26cde to your computer and use it in GitHub Desktop.
Save dakvid/f10a75cf490d065f9f8ed4dab5e26cde to your computer and use it in GitHub Desktop.
Plot the outlines of Auckland's local board areas
# #30DayMapChallenge 2021 - Day 3 - Polygons
# Displaying the local board ares of Auckland
# -- David Friggens, November 2021
library(magrittr)
library(dplyr)
library(tidyr)
library(stringr)
library(purrr)
library(sf)
library(rmapshaper)
library(ggplot2)
library(patchwork)
# from https://datafinder.stats.govt.nz
talb_full <- read_sf("territorial-authority-local-board-2021-clipped-generalised.gpkg")
# My initial thought was to plot all TAs, but 67 was just too much
lb_med <-
talb_full %>%
filter(TALB2021_V1_00 %>% str_detect("^076")) %>%
arrange(TALB2021_V1_00_NAME) %>%
ms_simplify(keep = 0.4, keep_shapes = FALSE)
PLOT_FONT <- "BellTopo Sans" # from https://www.sarahbellmaps.com/belltopo-sans-font-by-sarah-bell/
BG_COLOUR <- "#252a32"
TEXT_COLOUR <- "#dddddd"
TITLE_COLOUR <- "white"
# facet_wrap won't allow free scales with sf so I needed to
# plot each area separately and then join them with patchwork::wrap_plots
gg_lb <-
lb_med %>%
select(code = TALB2021_V1_00,
name = TALB2021_V1_00_NAME,
land_area = LAND_AREA_SQ_KM) %>%
mutate(name = name %>% str_replace("Local Board Area", "")) %>%
nest(lb = c("name", "land_area", "geom")) %>%
mutate(lb_plot =
lb %>%
map(~ ggplot(.x) +
geom_sf(fill = "3B454A",
size = 0.1,
color = "#b2b2b277") +
coord_sf(datum = NA) +
labs(title = .x$name) +
theme(plot.title = element_text(size = 14, family = PLOT_FONT, colour = TEXT_COLOUR, hjust = 0.5))
)
) %>%
pull(lb_plot) %>%
wrap_plots(ncol = 11) +
plot_annotation(title = "Auckland Local Board Areas",
subtitle = "#30DayMapChallenge 2021 - Day 3 - Polygons",
caption = "David Friggens @dakvid, Data: Stats NZ",
theme = theme(plot.title = element_text(size = 72, family = PLOT_FONT, colour = TITLE_COLOUR),
plot.subtitle = element_text(size = 32, family = PLOT_FONT, colour = TEXT_COLOUR),
plot.caption = element_text(size = 32, family = PLOT_FONT, colour = TEXT_COLOUR))) &
theme(plot.background = element_rect(fill = BG_COLOUR, colour = BG_COLOUR),
panel.background = element_rect(fill = BG_COLOUR, colour = BG_COLOUR))
gg_lb
ggsave(plot = gg_lb,
path = ".", filename = "Day_03_auckland_local_boards.png", device = "png",
width = 30, height = 9, dpi = 72)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment