Mapping thefts from vehicles in Vancouver
For this exercise, you should create the R code needed to make a dot map of thefts from vehicles in Vancouver in 2020.
Before you start
Complete Chapters 1–5 of Learn Crime Mapping with R.
In this exercise you will practise downloading and reading data, filtering rows, converting coordinates into a spatial object, and creating a point map. The coordinate-system codes needed for this dataset are supplied below.
What your map should show
Your map should show offences in the category ‘Theft from Vehicle’ that occurred in Vancouver in 2020. You can download the data from:
https://mpjashby.github.io/crimemappingdata/vancouver_thefts.csv.gz
See the dataset documentation for the columns and source. The X and Y columns use the UTM zone 10 north coordinate reference system (EPSG:32610), and the address column is anonymised to the nearest 100 block.
Your map should include:
- a layer showing (as points) the locations of individual thefts from vehicles,
- a suitable base map.
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 a map (and possibly some R messages or warnings), not output anything else (e.g. a copy of the data).
Checklist for this exercise
Use this checklist to make sure you have done everything required for this exercise.
The map
- The map shows the locations of individual crimes.
- The points use a colour that stands out from the background.
- You have made design choices that make it as easy as possible to show where thefts from vehicles are most concentrated.
The code
- There is no temporary code – e.g.
head()– in your script file. - The code loads the necessary packages at the start of the script in a single call to the
pacman::p_load()function. - The code uses
request()andreq_perform()to download the data to a local file in thedata/rawfolder. - The code uses
here()to specify file paths within your workspace. - The code loads the downloaded local file into R.
- The code converts all the column names in the data to
snake_caseand only uses snake-case object names. - The code converts the data to an SF object.
- The code filters the data to only include the type of crime you are interested in.
- The code uses the pipe operator
|>to link together functions into a data-wrangling pipeline.
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.