Propensity to Cycle Tool Training course


title: "Propensity to Cycle Tool Training course" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{pct_training} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} bibliography: ../vignettes/refs_training.bib


knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  out.width = "50%"
)
# get citations
refs = RefManageR::ReadZotero(group = "418217", .params = list(collection = "JFR868KJ", limit = 100))
refs2 = RefManageR::ReadBib("vignettes/refs.bib")
refs = c(refs, refs2)
citr::insert_citation(bib_file = "vignettes/refs_training.bib")
RefManageR::WriteBib(refs, "vignettes/refs_training.bib")
citr::tidy_bib_file(rmd_file = "vignettes/pct_training.Rmd", messy_bibliography = "vignettes/refs_training.bib")

These solutions assume you have worked through the exercises in the pct_training vignette and have loaded the necessary packages.

library(pct)
library(dplyr)   # in the tidyverse
library(tmap) # installed alongside mapvew

Getting and viewing PCT data

Answer: E02003582 Isle of Wight 002

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)
# the solution:
z_highest_cycling = z %>% 
  top_n(n = 1, wt = bicycle)

Answer: E02003582 Isle of Wight 002, check by viewing the data frame or using print()

plot(z$geometry)
plot(z_highest_cycling$geometry, col = "red", add = TRUE)

Answer:

E02003588 E02003591 654

E02003588 E02003589 615

E02003582 E02003588 567

E02003581 E02003588 485

E02003585 E02003588 406

# Aim: get top 5 cycle routes
l_original_msoa = get_pct_lines("isle-of-wight")
l_msoa = l_original_msoa %>% 
  select(geo_code1, geo_code2, all, bicycle, car_driver, rf_avslope_perc, rf_dist_km)
l = l_msoa
l_top_cycling = l %>% 
  top_n(n = 5, wt = bicycle)
plot(z$geometry)
plot(l_top_cycling, add = TRUE, lwd = 5, col = "green")

# top 5 driving routes
l_top_driving = l %>% 
  top_n(n = 5, wt = car_driver)
plot(z$geometry)
plot(l_top_driving, add = TRUE, lwd = 5, col = "red")
# at the lsoa level
l_original_lsoa = get_pct_lines("isle-of-wight", geography = "lsoa")
l = l_original_lsoa %>% 
  select(geo_code1, geo_code2, all, bicycle, car_driver)
l_top_cycling = l %>% 
  top_n(n = 5, wt = bicycle)
plot(z$geometry)
plot(l_top_cycling, add = TRUE, lwd = 5, col = "green")

# top 5 driving routes
l_top_driving = l %>% 
  top_n(n = 5, wt = car_driver)
plot(z$geometry)
plot(l_top_driving, add = TRUE, lwd = 5, col = "red")

Answer: LSOAs are samller than MSOAs, so provide more spatial detail. This can be useful. However MSOAs often give a better overview. For example MSOA anlaysis will highlight commuter travel to a single to a city centre. LSOA travel is often more chaotic with many origins and desinations.

As LSOAs are smaller they are more susetible to bias from outlieres, conisder how many people need to change behavoir for a 1% mode shift for and LSOA and MSOA.

# at the lsoa level
l_top_cycling = l %>% 
  top_n(n = 300, wt = bicycle)
plot(z$geometry)
plot(l_top_cycling, add = TRUE, lwd = l_top_cycling$bicycle / mean(l_top_cycling$bicycle), col = "green")

# top 5 driving routes
l_top_driving = l %>% 
  top_n(n = 300, wt = car_driver)
plot(z$geometry)
plot(l_top_driving, add = TRUE, lwd = l_top_driving$car_driver / mean(l_top_driving$car_driver), col = "red")

Modifying PCT data to identify routes/roads of interest

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))
rnet = get_pct_rnet("isle-of-wight")

Scenarios of change

l_msoa$euclidean_distance = as.numeric(sf::st_length(l_msoa))
l_msoa$pcycle_govtarget = uptake_pct_govtarget(
  distance = l_msoa$rf_dist_km,
  gradient = l_msoa$rf_avslope_perc
  ) * 100 + l_msoa$pcycle
l_msoa$pcycle_dutch = uptake_pct_godutch(
  distance = l_msoa$rf_dist_km,
  gradient = l_msoa$rf_avslope_perc
  ) * 100 + l_msoa$pcycle
plot(l_msoa["pcycle"], lwd = l_msoa$all / mean(l_msoa$all), breaks = c(0, 5, 10, 20, 50))
plot(l_msoa["pcycle_dutch"], lwd = l_msoa$all / mean(l_msoa$all), breaks = c(0, 5, 10, 20, 50))

Routing

library(stplanr)
l_top = l_msoa %>% 
  top_n(n = 1, wt = bicycle)
r_top = stplanr::route_osrm(l_top)
sf::write_sf(sf::st_as_sf(r_top), "r_top.geojson")
piggyback::pb_upload("r_top.geojson")
piggyback::pb_download_url()
r_top = sf::read_sf("https://github.com/ITSLeeds/pct/releases/download/0.0.1/r_top.geojson")
tm_shape(r_top) +
  tm_lines(lwd = 5)
r_cs = stplanr::line2route(l_top)
leaflet() %>% 
  addTiles() %>% 
  addPolylines(data = r_cs)

Route networks

route_data = sf::st_sf(wight_lines_30, geometry = wight_routes_30$geometry)
rnet_walk = overline2(x = route_data, "foot")
tm_shape(rnet_walk) +
  tm_lines(lwd = "foot", scale = 9)
# Demo PCT Analysis#
# Make a commuting quiet route network for Isle of Wight
# and combine it with the travle to school route network

# Step 1: Load Library
library(tidyverse)
library(sf)
library(pct)
library(stplanr)

# Step 2: Get Data
routes_commute = get_pct_routes_quiet(region = "isle-of-wight",
                              purpose = "commute",
                              geography = "lsoa")

lines_commute = get_pct_lines(region = "isle-of-wight",
                              purpose = "commute",
                              geography = "lsoa")

rnet_school = get_pct_rnet(region = "isle-of-wight",
                           purpose = "school",
                           geography = "lsoa")

# Step 3: Prepare Data
lines_commute = lines_commute %>%
  st_drop_geometry() %>%
  select(id, bicycle, dutch_slc)

routes_commute = routes_commute %>%
  select(id)

# Join Cycling Levels to Routes
routes_commute = left_join(routes_commute, lines_commute)
plot(routes_commute["bicycle"])

# Make a commuting Rnet
rnet_commute = overline2(routes_commute, 
                         attrib = c("bicycle","dutch_slc"))
plot(rnet_commute["bicycle"])

# Combine commuting and travel to schools
rnet_school <- rnet_school %>%
  select(dutch_slc)
rnet_commute <- rnet_commute %>%
  select(dutch_slc)
rnet_commute$bicycle <- NULL


rnet_both = rbind(rnet_commute, rnet_school)
rnet_both = overline2(rnet_both, 
                         attrib = c("dutch_slc"))
mapview::mapview(rnet_both, at = c(50,100,200,500,1000))


Try the pct package in your browser

Any scripts or data that you put into this service are public.

pct documentation built on May 31, 2023, 7:55 p.m.