Libraries code
library(tidyverse)
library(sf)
library(koordinatr)
library(ggdark)
library(ggfx)
library(ggtext)
Isaac Bain
June 25, 2024
Understanding the distribution of human populations is crucial for various applications, from urban planning to environmental management. Statistics New Zealand’s recently released 2022 Estimated Resident Population Grid provides an invaluable new resource for researchers, policymakers, and spatial analysts.
This dataset stands out due to its fine resolution. Previously, the highest resolution population information was available at the Statistical Area 1 (SA1) level, with SA1s typically having between 100-200 residents, and a maximum population of about 500. The critical thing here is that SA1s vary in size, being smaller in urban areas and larger in rural ones1.
Now, these population grid layers offer a much finer resolution, available at 250 metre2, 500 metre3, or 1000 metre4 sizes. To create these population grids, Stats NZ disaggregated population counts from larger geographic areas (i.e., meshblocks) into smaller regular grid cells. This was done using a combination of spatial interpolation methods and ancillary data, such as land use and residential building locations, to accurately distribute the population estimates across the grid.
I wanted to create something that resembled a satellite image or a photo from the International Space Station looking down on New Zealand at night, with the lights of all the different cities shining back (ignoring the fact this is also known as light pollution!).
Here’s two examples from Loss of the Night and NASA:
The data were provided in a rectangular regular grid, with counts of the Estimated Resident Population per grid cell. To address the wide range of values and maintain aesthetic appeal, a log-transform of the counts was applied. The legend was back-transformed to improve readability.
I used the ggfx
package to add an outer glow to the coastline, and the ggdark
package to create a dark theme for the plot. The colour scale was from the viridis
palette, which is a perceptually uniform colour scale that is designed to be colour blind-friendly.
ggplot() +
with_outer_glow(
geom_sf(data = coastline, fill = "black", colour = NA),
colour = "#262525",
sigma = 60,
expand = 30
) +
geom_sf(data = dat, aes(fill = log(ERP_2022)), colour = NA) +
scale_fill_viridis_c(
option = "plasma",
breaks = log(c(1, 5, 20, 100, 500)), # Adjust breaks for normal scale
labels = c("1", "5", "20", "100", "500"), # Corresponding labels
guide = guide_colourbar(title.position = "top", title.hjust = 0.5, direction = "horizontal")
) +
coord_sf(xlim = c(1050000, 2200000), ylim = c(4700000, 6200000)) +
ggdark::dark_theme_void(base_size = 14) +
theme(
legend.position = "inside",
legend.position.inside = c(0.75, 0.2),
legend.key.width = unit(1.25, "cm"),
legend.title = element_text(size = rel(0.7), hjust = 0.5, color = "#847E89"),
legend.text = element_text(color = "#847E89"),
plot.caption = element_text(color = "#847E89"),
plot.title = element_markdown(
family = "Baskerville",
size = rel(2.75),
color = "#C2D3CD",
hjust = 0.5,
margin = margin(14, 0, 4, 0)
),
plot.subtitle = element_markdown(
family = "Montserrat",
color = "#9FA4A9",
hjust = 0.5
)
) +
labs(
title = "People patterns in Aotearoa",
subtitle = "Population density from StatsNZ 2023 census data",
caption = "isaacbain.com",
fill = "Estimated Resident Population\n per 500m2"
)
I had a lot of fun making this population density map in a dark theme. The resulting visualisation not only highlights population patterns but also provides a visually striking representation of New Zealand’s demographic landscape.
The improvement in spatial resolution offered by this data could significantly enhance research applications. For instance, it enables more accurate distribution of populations onto river networks, allowing us to answer questions such as how many people live upstream of any given river segment.
Stay tuned for a future post on this topic.
The largest SA1 is in the south-west corner of the South Island, in Fiordland National Park covering 5800 km2. Whilst the smallest SA1 is a single building in central Wellington, covering 0.00064 km2.↩︎
https://datafinder.stats.govt.nz/layer/115047-new-zealand-2022-estimated-resident-population-grid-250-metre-2023/↩︎
https://datafinder.stats.govt.nz/layer/115050-new-zealand-2022-estimated-resident-population-grid-500-metre-2023/↩︎
https://datafinder.stats.govt.nz/layer/115051-new-zealand-2022-estimated-resident-population-grid-1-kilometre-2023/↩︎