Mapping stalking rates in Queensland

For this exercise, you must create the code needed to make a map of stalking incidents in the state of Queensland, Australia, in 2018.

Before you start

Complete Chapters 1–5, 7 and 9 of Learn Crime Mapping with R.

In this exercise you will practise downloading and reading data, data wrangling, combining multiple datasets and calculating rates, creating a choropleth map, and saving a map to a file.

What your map must show

Your map must show the incidence rate of stalking incidents in 2018 in each police division in Queensland. You will need three datasets to produce this map:

Stalking counts for each division in Excel format: https://mpjashby.github.io/crimemappingdata/qld_stalking.xlsx

Population data for each division in CSV format: https://mpjashby.github.io/crimemappingdata/qld_population.csv.gz

Police division boundaries in geopackage format: https://mpjashby.github.io/crimemappingdata/qld_police_divisions.gpkg

See the documentation for the stalking counts, population and police division boundaries for the columns and sources. The population figures are from 2016 and the boundaries are from 2022, while you are mapping offences from 2018. Your rates therefore use an earlier population count rather than the population in 2018. Acknowledge the Queensland Police Service for the offence counts and the Queensland Government for the boundaries, following the attribution licences listed in the documentation.

Your map must include:

  1. a layer showing the rate of stalking crimes in each division,
  2. a suitable base map,
  3. the contextual information (title etc.) needed to help readers understand the map properly.

If you want to make this exercise slightly more challenging, add a layer highlighting the 10 divisions with the highest stalking rates.

Every step of your code should be accompanied by an explanatory comment (on one or more lines starting with a # symbol and a space). Your code should only produce and save a map (and possibly some R messages or warnings), not output anything else (e.g. a copy of the data).

Your code should include the code needed to save your map in JPEG format, 2,000 pixels on each side.

Checklist for this exercise

Make sure you have checked that your map and code meet all of the following requirements.

The map

  • The map shows the incidence rate of stalking crimes in each division.
  • The incidence rates are shown using an appropriate sequential (not diverging or qualitative) colour scheme.
  • The most visually prominent colour indicates the highest rates of stalking.
  • The map shows the boundary of each police division.
  • The map includes a suitable base map.
  • The base map does not distract from the data layer or make it harder to see the data layer.
  • It is possible to see the base map through the layer that shows the stalking rate.
  • There is a declarative title and a descriptive subtitle.
  • The caption acknowledges the data sources where required.
  • You have made design choices that make it as easy as possible to show where the stalking rate is highest.
  • You have made design choices that make sure the boundaries do not obscure the places with the highest rates of crime.

The code

  • There is no temporary code – e.g. head() or install.packages() – in your script file.
  • The code loads all the necessary packages at the start of the script.
  • The code downloads the data file from the URL to a local file and then loads it.
  • The code converts all the column names in the data to snake_case and only uses snake-case object names.
  • The code converts the data to an SF object.
  • The code joins the datasets together correctly.
  • Every step of your code is accompanied by an explanatory comment.
  • The code produces an image file of the correct dimensions, not a dynamic web map.

Check your answer

After attempting the task, you can read this specimen answer and explanation to get an idea of what a potential solution looks like.