Skip to content

Commit 83faf60

Browse files
committed
Update stplanr slides
1 parent 725b04a commit 83faf60

1 file changed

Lines changed: 69 additions & 15 deletions

File tree

vignettes/stplanr-example.Rmd

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
---
2-
title: "**stplanr**: A package for transport planning"
2+
title: "An introduction to **stplanr**: A package for transport planning"
33
author: "Robin Lovelace, University of Leeds, [ITS](www.its.leeds.ac.uk/)/[LIDA](http://www.lida.leeds.ac.uk/)"
4-
date: "`r Sys.Date()"
4+
date: "`r Sys.Date()`"
55
output:
66
ioslides_presentation:
77
transition: slower
88
logo: ../figure/its-logo-square.png
99
---
1010

11-
```{r, include=FALSE}
12-
library(stplanr)
13-
library(sp) # needed for geographical objects
14-
library(leaflet) # needed for plotting data
15-
```
16-
17-
## Talk structure
11+
## Contents
1812

1913
> - Background
2014
> - Using stplanr
@@ -24,9 +18,9 @@ library(leaflet) # needed for plotting data
2418

2519
## Why **stplanr**
2620

27-
- I became lead developer of national research project funded by the Department for Transport
28-
- To create the **Propensity to Cycle Tool** (PCT)
21+
- Contracted to create the **Propensity to Cycle Tool** (PCT)
2922
- Best way to understand **stplanr** is via a live demo, at **[www.pct.bike](http://www.pct.bike/)**
23+
- Needed functions to work with origin-destination data and routing services
3024

3125
```{r, echo=FALSE}
3226
knitr::include_graphics("https://github.com/npct/pct/raw/master/flow-model/od-data-leeds.png")
@@ -62,10 +56,14 @@ it can be loaded in with `library()`:
6256

6357
```{r, eval=FALSE}
6458
install.packages("stplanr") # stable CRAN version
65-
devtools::install_github("ropensci/stplanr") # dev version
66-
library(stplanr)
59+
# devtools::install_github("ropensci/stplanr") # dev version
60+
```
61+
62+
```{r}
63+
library(stplanr) # also loads spatial package
6764
```
6865

66+
6967
> - Dev version requires rtools on Windows
7068
7169
## Why host on ROpenSci?
@@ -126,7 +124,45 @@ data("cents", package = "stplanr")
126124
as.data.frame(cents[1:3,-c(3,4)])
127125
```
128126

129-
## Creating 'desire lines'
127+
## Creating a single desire line
128+
129+
```{r}
130+
flow_single_line = flow[4,] # select only the first line
131+
desire_line_single = od2line(flow = flow_single_line, zones = cents)
132+
plot(cents)
133+
plot(desire_line_single, add = T)
134+
```
135+
136+
## What just happened?
137+
138+
- We selected a single 'od-pair' (`flow[4,]`)
139+
- The function `od2line()` matched the cents matching the lines and created a line (the hard bit)
140+
- How? Check the source code!
141+
142+
```{r}
143+
od2line
144+
```
145+
146+
## A hard-coded version:
147+
148+
```{r}
149+
o = cents[cents$geo_code %in% flow$Area.of.residence[4],]
150+
d = cents[cents$geo_code %in% flow$Area.of.workplace[4],]
151+
l_single = Lines(list(Line(rbind(o@coords, d@coords))), ID = 1)
152+
l_sp = SpatialLines(LinesList = list(l_single))
153+
```
154+
155+
## Visualising the result
156+
157+
```{r}
158+
plot(cents)
159+
points(o, cex = 5)
160+
points(d, cex = 5)
161+
flow[4, 1:3]
162+
plot(l_sp, add = TRUE)
163+
```
164+
165+
## Creating 'desire lines' for all flows
130166

131167
```{r, warning=FALSE}
132168
l <- od2line(flow = flow, zones = cents)
@@ -201,4 +237,22 @@ devtools::install_github("ropensci/stplanr")
201237
- Create issues on our [issue tracker](https://github.com/ropensci/stplanr/issues)
202238
- Check out the [vignette](https://cran.r-project.org/web/packages/stplanr/vignettes/introducing-stplanr.html)
203239
- See my tutorial on visualising spatial data for eRum: [Creating-maps-in-R/blob/master/vignettes/vspd-base-shiny.md](https://github.com/Robinlovelace/Creating-maps-in-R/blob/master/vignettes/vspd-base-shiny.md)
204-
- Academic paper on the PCT: http://arxiv.org/abs/1509.04425
240+
- Academic paper on the PCT: http://arxiv.org/abs/1509.04425
241+
242+
## Exercises
243+
244+
- Work through the [vignette](https://cran.r-project.org/web/packages/stplanr/vignettes/introducing-stplanr.html) provided by:
245+
246+
```{r, eval=FALSE}
247+
vignette("introducing-stplanr")
248+
```
249+
250+
- Create a single desire line for the 12th flow without using **stplanr** code (**stplanr** solution below):
251+
252+
```{r, eval=FALSE}
253+
od2line(flow = flow[12,], zones = cents)
254+
```
255+
256+
- Visualise the `flowlines` object using **tmap** with different colours and widths
257+
- Create a 'oneway' version of the `flowlines` and visualise these (tricky)
258+
- Create a **sf** version of the `flowlines` object (advanced)

0 commit comments

Comments
 (0)