An Introduction to the pct package

Obtaining and reproducing data from the Propensity to Cycle Tool (PCT)

Robin Lovelace and Layik Hama

2019-06-23

Introduction

The goal of the pct package is to increase the accessibility and reproducibility of the outputs from the Propensity to Cycle Tool (PCT), a research project and web application hosted at www.pct.bike. The tool is one of just ~300 central government websites exempt from the requirement to transition to the .gov.uk domain name, and is a recommended source of evidence in the preparation of Local Walking and Cycling plans (LCWIPs), as outlined in technical guidance1, supporting the Cycling and Walking Infrastructure Strategy (CWIS), an amendment of the Infrastructure Act 2015. For an overview of the data provided by the PCT, clicking on the previous link and trying it out is a great place to start. An academic paper on the PCT provides detail on the motivations and methods underlying the project2.

Since work on the package began in 2015, for example during the ODI Leeds Hack my Route hackathon (see an early prototype of the tool here), the features and demand for the PCT have evolved substantially. In early 2019, for example, the School travel layer was added to the main PCT site to provide evidence nationwide on the potential benefits of scenarios of cycling uptake, and where safe routes to school should be prioritised3. In fact, a major aim of the PCT was to enable people to extend the tool2:

We envision stakeholders in local government modifying scenarios for their own purposes, and that academics in relevant fields may add new features and develop new use cases of the PCT.

Motivated by this vision of adaptable transport planning tools, this introductory vignette demonstrates how the package works with an example from the Isle of Wight, an island just off the southern coast of Britain, with a population of ~140,000 people. Before demonstrating some of the package’s key functions, it’s worth providing a little context.

Why this package?

The Propensity to Cycle Tool was commissioned by the UK’s Department for Transport to help planners and others prioritise investment and policies to get people cycling, as outlined in the Government report National propensity to cycle: full report with annexes4. However, the academic team leading the project had a wider sub-aim: of making transport evidence more accessible, encouraging evidence-based transport policies, and encouraging a more democratic transport planning process, and that means open transport data and open source transport modelling tools2.

The code base underlying the PCT is publicly available (see github.com/npct). However, the code hosted there is not easy to run or reproduce, which is where this package comes in: it provides quick access to the data underlying the PCT and enables some of the key results to be reproduced quickly. It was developed primarily for educational purposes (including for upcoming PCT training courses) but it may be useful for people to build on the the methods, for example to create a scenario of cycling uptake in their town/city/region.

In summary, if you want to know how PCT works, be able to reproduce some of its results, and build scenarios of cycling uptake to inform transport policies enabling cycling in cities worldwide, this package is for you!

Installation

You can install the development version of the package as follows:

remotes::install_github("ITSLeeds/pct")

Load the package as follows:

library(pct)

We will also use the following packages in this tutorial:

library(sf)
library(stplanr)
library(leaflet)

Get PCT data

From feedback, we hear that the use of the data is critical in decision making. Therefore, one area where the package could be useful is making the data “easily” available to be processed.

To download the data within www.pct.bike, we have added a suite of functions:

There are other get_() functions that get official data underlying the PCT, as we will see in a later section. For now, let’s see how the functions work. To get the centroids in Isle of Wight, you would run:

library(pct)
wight_centroids = get_pct_centroids(region = "isle-of-wight")
wight_zones = get_pct_zones(region = "isle-of-wight")

Let’s verify that the data gave us what we would expect to see:

plot(wight_centroids[, "bicycle"])
plot(wight_zones[, "bicycle"])

The results are indeed as we would expect, with the centroid data showing points and the zone data showing zones. The zones with higher cycling levels are in the more densely populated south of the island, as we would expect. Likewise, the following command downloads the desire lines for the Isle of Wight:

wight_lines_pct = get_pct_lines(region = "isle-of-wight")

The rest of the get_pct_ functions are similar to the above two examples and download data from www.pct.bike.

However, the base of these functions is get_pct(), which takes the following arguments:

Comparing downloaded data with the PCT web app

To compare the downloaded data with data in the PCT web app, we will take a subset of the wight_lines_pct dataset. The top 30 travelled desire lines by number of commuters who use cycling as their main mode is taken in the following code chunk. The reason for selecting the top 30 will become apparent (the wight_lines_30 object is provided in the PCT package):

line_order = order(wight_lines_pct$bicycle, decreasing = TRUE)
wight_lines_30 = wight_lines_pct[line_order[1:30], ]

The resulting wight_lines_pct and wight_lines_30 datasets are available in the package. We’ll use the smaller one for speed. Note: these contain many variables, three of which (the number of people cycling, driving and walking along the desire lines from the 2011 Census) are shown below for the Isle of Wight:

lwd = wight_lines_30$all / mean(wight_lines_30$all) * 5
plot(wight_lines_30[c("bicycle", "car_driver", "foot")], lwd = lwd)

To provide another view of the data, focus on cycling, let’s create a leaflet map:

pal = colorNumeric(palette = "RdYlBu", domain = wight_lines_30$bicycle)
leaflet(data = wight_lines_30) %>% 
  addTiles() %>% 
  addPolylines(weight = lwd,
               color = ~ pal(bicycle)) %>% 
  addLegend(pal = pal, values = ~bicycle)

There was a reason for selecting the top 30 lines: it mirrors the view of the desire lines available from the PCT web application for the island, available at www.pct.bike/m/?r=isle-of-wight (note that Straight Lines is selected from the Cycling Flows dropdown menu in the image below, and by default shows the top 30 flows by number of bicycle trips).