Code
library(sf)
library(ggplot2)
library(dplyr)
I made an alternative version of this map for some slides. It shows off the little-known multiplication by an affine transform matrix superpower that sf
somewhat surprisingly admits (it felt like a cheat-code when I came across it here).
Here’s the superpower in action where we make an affine rotation matrix and multiply the geometries in the dataset by it. You can use similar operations to translate geometries, although keeping everything lined up can be tricky.
Reading layer `nz-2193' from data source
`/Users/david/Documents/code/computing-geographically/chapters/chap4/nz-2193.gpkg'
using driver `GPKG'
Simple feature collection with 1 feature and 0 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 1089973 ymin: 4748123 xmax: 2089535 ymax: 6194308
Projected CRS: NZGD2000 / New Zealand Transverse Mercator 2000
Reading layer `placenames' from data source
`/Users/david/Documents/code/computing-geographically/chapters/chap4/placenames.gpkg'
using driver `GPKG'
Simple feature collection with 47417 features and 9 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 502051.1 ymin: 4460560 xmax: 2239532 ymax: 6638458
Projected CRS: NZGD2000 / New Zealand Transverse Mercator 2000
And now a map with colour choices in large measure dictated by the slides I was making this map for.
As noted in the book, the materials for this figure draw on the amazing work of Chris McDowall and Tim Denee in their We Are Here atlas, the Toitū Te Whenua – Land Information New Zealand gazetteer of placenames, and on Te Hiku Media’s Ngā-kupu tools.
# License (MIT)
#
# Copyright (c) 2023 David O'Sullivan
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
© 2023-24 David O’Sullivan