This repository contains presentation materials for Mapping with R: Static, Dynamic, and Mapped as presented live in Melbourne for the Data Vizualisation Society and on YouTube. The files are:
README.Rmd: This file.README.md: Knit output for easy display on GitHub.dataVizMaps.qmd: Quarto file, including code chunks, image links, and plain text.jobsOct2022.xlsx: Excel data file from the Australian Bureau of Statistics (ABS).- Presentation Images:
jobsDataSS.png: Screenshot of the Excel file for an overview of the input data.asgsGeography.png: Screenshot of the geography standards used by the ABS.mapMeme.jpg: Meme of putting maps in your map.mapnmap.jpg: Image export of the maps-in-a-map concept.leafletReference.jpg: Screenshot of news article that uses Leaflet as part of their data journalism. My aim is to provide examples where Leaflet is used in the “real-world” and give you confidence that you can make similar visualisations yourself.- There were other pictures of me at various points in my professional journey, but I’ve removed them.
- Branding:
logo.css: Scaled my consulting company logo. I was also playing with some of the code window settings but went back to the default. Use it to try to customise things if you’d like.img/Doc_SS_Black-01.png: My company logo.
The following exceptions are noted:
- Map Tooltips: The maps-in-a-map works interactively, but something in the file organisation structure in Quarto doesn’t align with the file outputs.
If you run the code interactively (rather than through rendering the document), it should work for you.
To do this:
- Launch
RStudiowith thedataVizMaps.qmdfile. - Ensure all the libraries are installed, including
wfmackey/absmapsdatafrom Github. - Check that you have the Excel data file.
- Find the
mapFunctioncode chunk . - Execute the previous chunks with the down arrow on the upper-right of the code chunk.
- Execute the
mapFunctionchunk. This should generate thesa4MappedMapvariable. - Interactively view
sa4MappedMap. This should display the maps-in-a-map in theRStudioviewer pane.
- Data: The example data provided are in Excel and seem to be
manually extracted and stored. If you get future data, the sheet
name, skip parameter, and variable order may shift. Further, the
absmapsdatapackage is available from GitHub but is quite large. You might need to adapt thetimeoutparameter to get it to install, depending on the speed of your connection.
As absmapsdata is a user-maintained package (go give some love to
wfmackey while you’re there), note that future updates may change
variable names and/or formats.
- Images: I’ve included some of the images I used in the presentation but I’ve omitted photos of me that I included in the live presentation.
Data have been sourced from the Australian Bureau of Statistics, with the latest data being from October, 2022. The data are in Excel with a small amount of tidying required for the data.
Similar means are used to tidy the data for SA4 and SA3 geographies
using the tidyverse, including:
* Use of tidyr::separate1 to break the SA4 column into its code
and name parts.
* Use of tidyr::pivot_longer to get the dates into a column rather
than wage index by date. * Various dplyr calls to format values
(e.g., align Excel dates, etc).
Further, geographic information are from the absmapspackage, as
available on GitHub as
wfmackey/absmapsdata. Note
the package is large, so you might need to adjust the timeout options.
There are other examples of making maps on that page.
The code contains three types of maps, as hinted in the subtitle.
- Static: Made with
ggplot- a good starting point, and useful if your reports are PPT, PDF, etc. - Dynamic: Made with
leaflet. As the plots are HTML/JS based, you’ll need a browser or theRStudioviewer for these plots. - Mapped: Considerations on using the
purrr::mapfunction to generate many maps - whether static or dynamic.
A basic introduction to maps with ggplot, as it’s likely the first
graphing tool you’ll use when learning R. For advanced usage, I
recommend the ggmap package and the examples therein. Note that Google
has changed some of their usage terms to require authentication and a
credit card, but not all of the providers require this.
While I use leaflet to make some maps with custom tooltip (or label)
information, there are many other configuration options. The leaflet
for R page has some great examples.
Other dynamic map tools for R exist; I’ve used highcharter before
and it works well.
I’ve mainly included this as a play on words, as “You can use map to
put maps in your map” has a certain ring to it. There’s a bit of a
caveat here, in that you can use map to create maps quite efficiently,
but the usability of hundreds of maps is limited by human capacity to
retain information.
Footnotes
-
Oh, it seems
separateis deprecated. Huh. ↩
