-
Start off by attaching the tidyverse with the
library()
function. -
Create (or recreate) an object called
ac_wy
with the commandread_csv()
(you may need to first download the file from https://github.com/ITSLeeds/highways-course/releases ) -
What is the class of the
ac_wy
? -
Create a plot of dataset using ggplot2, resulting in a plot that looks a little like this (hint: set transparency with
alpha
ingeom_point()
, fix the coordinates with+ coord_equal()
): -
Building on the previous plot, make the size of each dot proportional to the number of people involved (
Number_of_Casualties
). -
Filter the dataset so that it contains only rows with
Accident_Severity
values ofKilled
orSerious
(hint:!= "Slight"
may help!). -
Further reduce the dataset size by selecting only the following columns for further analysis:
Accident_Index, Location_Easting_OSGR, Location_Northing_OSGR, Accident_Severity, Date, Speed_limit
. -
Load the sf library.
-
reate an object called
ac_wy_sf
, a spatial version of theac_wy
dataset read-in previously (hint: use the functionst_as_sf()
and coordinate variables Location_Easting_OSGR/Location_Northing_OSGR — set the CRS withcrs = 27700
) -
Plot the result with tmap, showing accident severity (hint: the code below plots the result for the speed limit).
library(tmap) tm_shape(ac_wy_sf) + tm_dots("Speed_limit")
-
Set the mode of tmap to viewing with
tmap_mode("view")
and run the previous command again to create an interactive map. -
Use this to visually identify a junction with many crashes.
-
Read-in a dataset representing Leeds with the following command (note: you need to have downloaded the file from https://github.com/ITSLeeds/highways-course/releases ):
leeds = readRDS("leeds.Rds")
-
Find the CRS of
leeds
withst_crs()
-
Transform the CRS to OSGB with the command
st_transform()
(hint: OSGB has the EPSG code 27700). -
Find out how many fatal and serious crashes happened in each of the MSOA areas in Leeds
- Advanced 1: Find out which MSOA zone had the highest average number of people in crashes
- Advanced 2: Look-up packages for clustering (hint: look at https://geocompr.github.io/geocompkg/articles/ )
- Advanced 3 (difficult): Aggregate point to regular grid cells