Welcome to pct-demo, a small repo with a little code and data to how how the pct works.
The starting point is that regional data has already been generated. See pct-scripts or an academic paper on the subject (Lovelace et al. 2017).
We also assume your have R and RStudio installed and running on your computer. There is plenty of guidance online, notably on the RStudio website: rstudio.com.
The first step is to download the the repo https://github.com/npct/pct-demo/archive/master.zip - that contains both code and data. Note that it contains a .qgs file that can be opened with the open source program QGIS - another powerful tool for analysing the geographical distribution of cycling potential.
The remainder of this tutorial is based on R code, which can be found in the code folder. We encourage you to look over these scripts. The script to load-in the data, for example, can be opened with the following command:
file.edit("code/load-data.R")
Once that file is open we can run it line-by-line, e.g. by pressing Ctl-Enter
. Alternatively you can entirety of a script file with the source()
function.
There are some dependencies: you need to have some packages installed.
source("code/set-up.R")
## Loading required package: sp
## Linking to GEOS 3.5.1, GDAL 2.2.1, proj.4 4.9.2, lwgeom 2.3.3 r15473
To load the input data, we can run the following script:
source("code/load-data.R")
The input data we have just loaded can be seen by looking in the Environment tab in RStudio. Alternatively you can use the function ls()
:
ls()
## [1] "cents" "l" "pkgs" "rf" "rnet"
## [6] "rq" "to_install" "z"
This shows that we have loaded the following data objects:
z
, administrative zones about which we have cycling datacents
, population-weighted centroids, one per zonel
, straight 'desire lines' representing travel between one zone and anotherrf
route-level data, likel
but allocated to the road network
We can plot all these layers interactively as follows:
library(tmap)
tmap_mode("view")
## tmap mode set to interactive viewing
qtm(z, "bicycle") +
qtm(cents) +
qtm(l) +
qtm(rf, col = "green")