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:
This is an advanced training course with specific pre-requisites. Please only register if you:
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).
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:
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:
To test your computer is ready to work with PCT data in R, try running the following commands.
We are testing a new method for helping people set up their computers. Type this single line into the console and follow the instructions.
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.
# 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`)
Break and presentation of results
The PCT provides data at 4 geographic levels:
Which types of data are most appropriate to tackle each of the questions/problems you identified?
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):
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 = TUREand a
colargument 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.
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).
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.
pcycleto the object
l_msoathat 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).
uptake_pct_godutch()(hint: the following code chunk will create a ‘Government Target’ scenario):
pct_uptake_godutch()- how could it be modified?
route_osrm()find the route associated with the most cycled desire line in the Isle of Wight. The result should look similar to that displayed in the map below (hint: you may want to start your answer with the following lines of code - warning: the function may need to run a few times before it works):
R2: What are the problems associated with this route from a cycling perspective? Take a look at the help page opened by entering
?route_osrm to identify the reason why the route is not particularly useful from a cycling perspective.
R3: Regenerate the route using the function
line2route(). What is the difference in the length between each route, and what other differences can you spot? Note: this exercise requires an API Key from CycleStreets.net.
R4 (bonus): what features of a routing service would be most useful for your work and why?
overline2()function and begin the script as follows, the results should look similar to the results below):
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.