-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
68 lines (46 loc) · 2.33 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
title: "Demonstrating the PCT, for education and reproducibility"
output: github_document
---
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](https://github.com/pctbike/pct-scripts) or an academic paper on the subject ([Lovelace et al. 2017](https://www.jtlu.org/index.php/jtlu/article/view/862)).
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](https://www.rstudio.com/products/rstudio/download/).
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](http://qgis.org/) - 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](https://github.com/npct/pct-demo/tree/master/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:
```{r, eval=FALSE}
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.
```{r}
source("code/set-up.R")
```
To load the input data, we can run the following script:
```{r, results='hide'}
source("code/load-data.R")
```
## Zones, centroids, lines, routes
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()`:
```{r}
ls()
```
This shows that we have loaded the following data objects:
- `z`, administrative zones about which we have cycling data
- `cents`, population-weighted centroids, one per zone
- `l`, straight 'desire lines' representing travel between one zone and another
- `rf` route-level data, like `l` but allocated to the road network
We can plot all these layers interactively as follows:
```{r}
library(tmap)
tmap_mode("view")
qtm(z, "bicycle") +
qtm(cents) +
qtm(l) +
qtm(rf, col = "green")
```