Repository navigation
Expand file tree
/
Copy pathREADME.Rmd
More file actions
109 lines (79 loc) · 2.91 KB
/
Copy pathREADME.Rmd
File metadata and controls
109 lines (79 loc) · 2.91 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
output: github_document
---
<!-- badges: start -->
[](https://github.com/cyclestreets/cyclestreets-r/actions) [](https://CRAN.R-project.org/package=cyclestreets)
[](https://github.com/cyclestreets/cyclestreets-r/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# cyclestreets
The goal of cyclestreets is to provide a simple R interface to the CycleStreets routing service.
It was split-out from **stplanr** for modularity.
## Installation
You can install the released version of cyclestreets from [CRAN](https://CRAN.R-project.org) with:
```{r install, eval=FALSE}
install.packages("cyclestreets")
```
Install the development version with **devtools** as follows:
```{r installdev, eval=FALSE}
# install.packages("devtools")
devtools::install_github("cyclestreets/cyclestreets-r")
```
## Example
A common need is to get from A to B:
```{r example}
library ("cyclestreets")
# stplanr::geo_code ("leeds rail station")
from = c(-1.544, 53.794)
# stplanr::geo_code ("leeds university")
to = c(-1.551, 53.807)
r = cyclestreets::journey(from, to, "balanced")
sf:::plot.sf(r)
```
To get a key go to <https://www.cyclestreets.net/api/apply/>
Save the key as an environment varible using `export CYCLESTREETS=your_key_here` by adding `CYCLESTREETS=your_key_here` as a new line in your `.Renviron` file, e.g. with the following command:
```{r, eval=FALSE}
usethis::edit_r_environ()
```
Check the map is good with leaflet:
```{r, eval=FALSE}
library(leaflet)
p = colorNumeric("RdYlBu", domain = r$quietness, reverse = TRUE)
leaflet(r) %>%
addTiles() %>%
addPolylines(color = ~p(quietness), weight = 20, opacity = 0.9) %>%
addLegend(pal = p, values = ~quietness)
```
Or **tmap**, highlighting the recently added 'quietness' variable:
```{r, eval=FALSE}
library(tmap)
tmap_mode("view")
tm_shape(r) + tm_lines("quietness", palette = "RdYlBu", lwd = 3)
```
```{r, echo=FALSE}
library(tmap)
tmap_mode("view")
m = tm_shape(r) + tm_lines("quietness", palette = "RdYlBu", lwd = 3)
tmap_save(m, "m.html")
webshot2::webshot("m.html")
```
See an interactive version of this map, showing all variables per segment, [here](https://rpubs.com/RobinLovelace/784236).
Or **mapview**:
```{r, eval=FALSE}
mapview::mapview(r)
```
Route types available are: fastest, quietest, balanced.
See help pages such as `?journey` and <https://www.cyclestreets.net/api/> for details.
You can also get streets by LTN status.
```{r}
network_ltns = ltns(r)
plot(network_ltns)
```