# Introduction

This vignette supports workshops on advanced usage and development of the Propensity to Cycle Tool (PCT). Beginner and intermediate PCT events focus on using the PCT via the web application hosted at www.pct.bike and the data provided by the PCT in QGIS.

The focus here is on analysing cycling potential in the open source statistical programming language R, in which the majority of the PCT was built. It will show how the code underlying the PCT works, how the underlying data can be accessed for reproducible analysis, and how the methods can be used to generate new scenarios of cycling uptake.

There will be 2 courses:

• In London on Friday 21st June
• In Leeds on Friday 2nd August (TBC)

# Prerequisites

This is an advanced training course with specific pre-requisites. Please only register if you:

• Have experience analysing geographic area and route data of the type used in the PCT
• Have experience using software for geographic data, including working knowledge of the statistical programming language R
• Can bring a laptop that has up-to-date versions of R, RStudio and the necessary R packages installed (see next section)

In addition, if you want to do routing on your computer:

If you are new to R this course may not be appropriate for you. If you are an intermediate user, it may be worth brushing-up on your R skills, e.g. by taking a free online course such as that provided by DataCamp or by working through Chapter 2 onwards of the open source book Geocomputation with R (see reading list below for more transport-specific resources).

## Prior reading

In addition to computer hardware (a laptop) and software (an up-to-date R set-up and experience using R) pre-requisites, you should have read, or at least have working knowledge of the contents of, the following publications, all of which are freely available online:

## R packages

To ensure your computer is ready for the course, please test that you can run the following lines of R code on your computer, resulting in the map shown below:

install.packages("remotes")
pkgs = c(
"cyclestreets",
"mapview",
"pct",
"sf",
"stats19",
"stplanr",
"tidyverse",
"devtools"
)
remotes::install_cran(pkgs)
# remotes::install_github("ITSLeeds/pct")

## Test code

To test your computer is ready to work with PCT data in R, try running the following commands.

### Option 1: New Method

We are testing a new method for helping people set up their computers. Type this single line into the console and follow the instructions.

source("https://raw.githubusercontent.com/ITSLeeds/TDS/master/code-r/setup.R") 

### Option 2: Old Method

If the new method does not work or you would like to be more hands on. Recreate the code below. It should result in the map below showing the % of short trips in West Yorkshire made by active modes.

library(pct)
library(dplyr)   # in the tidyverse
library(leaflet) # installed alongside mapvew
zones_all = get_pct_zones("west-yorkshire")
lines_all = get_pct_lines("west-yorkshire")
# basic plot
plot(zones_all$geometry) plot(lines_all$geometry[lines_all$all > 500], col = "red", add = TRUE) # interactive plot active = lines_all %>% mutate(Percent Active = (bicycle + foot) / all * 100) %>% filter(e_dist_km < 5) pal = colorBin(palette = "RdYlBu", domain = active$Percent Active, bins = c(0, 2, 4, 10, 15, 20, 30, 40, 90))
leaflet(data = active) %>%
addProviderTiles(providers$OpenStreetMap.BlackAndWhite) %>% addPolylines(color = ~pal(Percent Active), weight = active$all / 100) %>%
addLegend(pal = pal, values = ~Percent Active)

We can also use the data to explore entrenched car dependence, as follows:

# car dependent desire lines
car_dependent = lines_all %>%
mutate(Percent Drive = (car_driver) / all * 100) %>%
filter(e_dist_km < 5)
pal = colorBin(palette = "RdYlBu", domain = car_dependent$Percent Active, bins = c(0, 20, 40, 60, 80, 100), reverse = TRUE) leaflet(data = car_dependent) %>% addProviderTiles(providers$OpenStreetMap.BlackAndWhite) %>%
addPolylines(color = ~pal(Percent Drive), weight = active$all / 100) %>% addLegend(pal = pal, values = ~Percent Drive) # Agenda • 09:30 - 10:00: Arrival and set-up • 10:00 - 11:00: Data and methods underlying the PCT • 11:00 - 12:30: Getting and analysing PCT data • Comparing PCT results with existing road infrastructure • Getting data from the CyIPT • Identfying ‘weak links’ • Identify gaps in the network Lunch break • 13:30 - 15:30: Extending the PCT: minihack • Alternative scenarios of cycling uptake • A ‘replace short car trips’ scenario • New input data • Travel to stations • Other extensions of the PCT Break and presentation of results • 16:00 - 16:30: Policy implementation • Building open source web applications • Community-building • User interface • Policy uptake # Exercises ## How the PCT works and what you can use it for • Take a look at the image below from (Lovelace et al. 2017). Which parts of the process are of most use for your work? • In groups of 2, identify 3 real world questions/problems that you could use the PCT to help answer/solve The PCT provides data at 4 geographic levels: • Zones • Desire lines • Routes • Route networks Which types of data are most appropriate to tackle each of the questions/problems you identified? • Name 3 limitations of the data currently provided by the PCT and discuss how you could overcome them ## Getting and viewing PCT data • G1: Using the PCT’s online interface, hosted at www.pct.bike/m/?r=isle-of-wight, identify the MSOA zone that has the highest number of people who cycle to work. • G2: Using data downloaded with the command get_pct_zones(), identify the zone that has highest level of cycling with the function top_n() and save the result as an object called z_highest_cycling (hint: you may want to start by ‘cleaning’ the data you have downloaded to include only a few key columns with the function select(), as follows): library(pct) library(dplyr) # suggestion: use library(tidyverse) z_original = get_pct_zones("isle-of-wight") z = z_original %>% select(geo_code, geo_name, all, bicycle, car_driver) • G3: Use the plot() command to visualise where on the Ilse of Wight this ‘high cycling’ zone is (hint: you will need to use the plot() function twice, once to plot z$geometry, and again with the argument add = TURE and a col argument to add the layer on top of the base layer and give it a colour). The result should look something like something this:

• G4: Using the online interface, identify the top 5 MSOA to MSOA desire lines that have the highest number of people who cycle to work.

• G5: Using the function get_pct_lines(), identify the top 5 MSOA to MSOA desire lines that have the highest number of people who cycle to work (hint: you might want to start with the code shown below).
• Bonus: also find the 5 desire lines with the highest number of people driving to work. Plot them and find the straight line distance of these lines with the function st_distance().
# Aim: get top 5 cycle routes
l_original = get_pct_lines("isle-of-wight")
l_msoa = l_original %>%
select(geo_code1, geo_code2, all, bicycle, car_driver, rf_avslope_perc, rf_dist_km)
• G6 (Bonus): Repeat the exercise but for LSOA to LSOA desire lines (by setting the argument geography = "lsoa"). The results should look something like this:
• G7: Why are the results different? What are the advantages and disadvantages of using smaller zones, as represented by the LSOA data above?

• G8 (bonus): do the same analysis but with the top 300 routes cycled and driven. Hint: set the line width with lwd = l_top_cycling$bicycle / mean(l_top_cycling$bicycle) to portray the relative importance of each route.

## Modifying PCT data to identify routes/roads of interest

• M1: Building on the example above, add a new column called pcycle to the object l_msoa that contains the % who cycle to work (hint: you might want to start this by typing l_msoa$pcycle = ...) and plot the results (shown in left hand panel in plot below). l_msoa$pcycle = l_msoa$bicycle / l_msoa$all * 100
# plot(l_msoa["pcycle"], lwd = l_msoa$all / mean(l_msoa$all), breaks = c(0, 5, 10, 20, 50))
• M2 (bonus): identify road segments with the highest estimated number of people cycling currently, and under the Go Dutch scenario (hint: you can download the route network with get_pct_rnet("isle-of-wight"))

## Scenarios of change

• S1: Generate a ‘Go Dutch’ scenario for the Isle of Wight using the function uptake_pct_godutch() (hint: the following code chunk will create a ‘Government Target’ scenario):
l_msoa$euclidean_distance = as.numeric(sf::st_length(l_msoa)) #> Linking to GEOS 3.5.0, GDAL 2.2.2, PROJ 4.8.0 l_msoa$pcycle_govtarget = uptake_pct_govtarget(
distance = l_msoa$rf_dist_km, gradient = l_msoa$rf_avslope_perc

## Ideas for further work and a ‘minihack’

• Create a route network reflecting where you would invest if the priority was reducing car trips of less than 5 km
• Design interventions to replace short car trips across London (or another region of your choice) using the PCT methods/data to support your decisions
• Identify quiet routes and design a quiet route network for city/region of your choice, e.g. Westminter
• Import alternative origin-destination datasets and use those as the basis for propensity to cycle analysis for trip purposes other than single stage commutes, encapsulated in the commut layer in the PCT
• Any other layers/scenarios/hacks: welcome! Comments in this repo’s issue tracker also welcome.

# References

Lovelace, Robin, Anna Goodman, Rachel Aldred, Nikolai Berkoff, Ali Abbas, and James Woodcock. 2017. “The Propensity to Cycle Tool: An Open Source Online System for Sustainable Transport Planning.” Journal of Transport and Land Use 10 (1). https://doi.org/10.5198/jtlu.2016.862.

Lovelace, Robin, Jakub Nowosad, and Jannes Meunchow. 2019. Geocomputation with R. CRC Press. http://robinlovelace.net/geocompr.