-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
179 lines (134 loc) · 7.97 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
---
title: "AccessUK"
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
dpi=600,
collapse = TRUE,
message = FALSE
)
```
<img align="right" src="man/figures/logo.png" alt="logo" width="180">
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html)
`AccessUK` is an open-source tool for the R programming language designed to streamline the integration of accessibility measures into R workflows focusing on Great Britain (GB), thereby unlocking the potential of spatial data by informing decision-making processes and supporting sustainable practices across diverse sectors.
The main aim of this tool is to manage and distribute a series of pre-computed Accessibility-related measures for small geographic areas in GB described [here](https://www.nature.com/articles/s41597-023-02890-w) (PTAI dataset). The pre-computed measures include accessibility to employmnet, heath, education, food services, and urban centres. It offers additional functions that enable users to customise or create new accessibility measures.
`AccessUK` uses [`DuckDB`](https://duckdb.org/), a relational database management system optimised for analytical workloads, in the background. This facilitates the rapid execution of queries without loading the full data into virtual memory. This mitigates common computational challenges associated with large travel matrices.
## Installation
To install the latest version of `AccessUK` directly from GitHub, please follow the steps below:
### 1. Install the `devtools` package (if not already installed)
You'll need the `devtools` package to install R packages from GitHub. If you don't have it installed, run:
```R
install.packages("devtools")
```
### 2. Install AccessUK
With devtools installed, you can now install the AccessUK package:
```R
devtools::install_github("urbanbigdatacentre/AccessUK")
```
## Usage
`AccessUK` does three main things: (1) get ready-to-use accessibility measures for a range of urban and regional services; (2) tailor accessibility measures to destinations not previously included in the dataset based on pre-computed travel matrices; (3) estimate new accessibility measures based on user-generated TTMs and service locations.
```{r message=FALSE, warning=FALSE}
library(AccessUK)
library(tidyverse)
library(sf)
```
### 1. Getting precomputed accessibility measures
To get precomputed measures, the first step is to define a list 2011 lower super output areas (LSOA) or data zones (DZ) code for the desired locations. the example below selects a few areas in central London,
```{r}
lsoa_london <- c('E01000919', 'E01002726', 'E01003014', 'E01033490', 'E01000914', 'E01000937', 'E01032583', 'E01000855', 'E01003016', 'E01000918', 'E01000002', 'E01032739', 'E01000916', 'E01004734', 'E01000936', 'E01004735', 'E01002724', 'E01000850', 'E01033596', 'E01000852', 'E01000853', 'E01003927', 'E01033595', 'E01004731', 'E01000001', 'E01003935', 'E01004763', 'E01004736', 'E01000917', 'E01003929', 'E01003013', 'E01032740', 'E01032582', 'E01000915', 'E01003930', 'E01000920', 'E01003017', 'E01003934', 'E01004733', 'E01032584')
```
The desired locations are passed to the `get_accessibility()` function. Also, the type of destination can be specified in the 'service' argument. It can be chosen from "employment", "supermarkets", "school", "gp" (general practice), "hospital", and "cities". The example below retrieves accessibility to employment in central London.
```{R}
accessibility_london <- get_accessibility(
from = lsoa_london,
service = 'employment',
mode = "public_transport"
)
glimpse(accessibility_london)
```
The results include both the absolute employment available for a range of travel times in minutes as well as the relative employment in percent.
### 2. Tailored accessibility measures
Given new point locations in GB, the user can tailor its own accessibility measures at the LSOA/DZ level. This uses 2011 LSOA/DZ geometries in the background. This is combined with pre-computed travel times in the [PTAI dataset](https://www.nature.com/articles/s41597-023-02890-w). The example below uses retail points and for various time cuts.
```{r}
# New destination points for this example
data_dir = system.file('data', package = "AccessUK")
load(file.path(data_dir, 'retail_points.RData'))
retail_points <- retail_points %>%
st_as_sf(coords = c('long_wgs', 'lat_wgs'), crs = 4326)
# Run my_accessibility
timecuts <- c(10, 20, 30)
retail_accessibility <- my_accessibility(
destinations = retail_points,
time_cut = timecuts
)
glimpse(retail_accessibility)
```
The result includes accessibility for all of GB, given that the retail points cover all the territory. However, we visualise a subset in central London.
```{r}
# Read LSOA geometries
lsoa_geoms <- st_read(file.path(data_dir, 'lsoa_geoms/infuse_lsoa_lyr_2011_clipped.shp'))
# Map
retail_accessibility %>%
filter(from_id %in% lsoa_london) %>%
left_join(lsoa_geoms, by = c('from_id' = 'geo_code')) %>%
st_as_sf() %>%
ggplot() +
geom_sf(aes(fill = access_n_30), col = NA) +
scale_fill_viridis_c() +
labs(
title = 'Accessibility to retail points in London by public transport within 30 minutes',
subtitle = 'Contains retail points larger than 280 m2',
fill = 'Retail points'
) +
theme_void()
```
### 3. Compute new accessibility measures
The user can estimate completely new accessibility measures using `DuckDB` in the background for any region by providing a travel matrix in `CSV` or `Parquet` format. The user should input aggregated locations using the same ID as the travel matrix. This can contain different types of locations in each column with the first column named "id".
```{r}
# Aggregate locations in Manchester by LSOA
aggregated_retail <- retail_points %>%
filter(town == 'Manchester') %>%
my_accessibility(0)
# First column as 'id'
aggregated_retail <- aggregated_retail %>%
rename(retail = access_n_0, id = from_id)
# Specify the location of a travel matrix. This can be a folder with multiple files or a single file
ttm_path <- file.path(data_dir, 'accessibility_indicators_gb/ttm/ttm_pt_20211122.csv')
# Estimate accessibility for various thresholds
new_accessibility <- estimate_accessibility(
travel_matrix = ttm_path,
travel_cost = 'travel_time_p50',
weights = aggregated_retail,
time_cut = timecuts
)
glimpse(new_accessibility)
```
This returns all LSOA/DZ in GB. As we are providing data for Manchester only, we can filter relevant observations only.
```{r}
new_accessibility %>%
filter(access_retail_20 > 0) %>%
left_join(lsoa_geoms, by = c('from_id' = 'geo_code')) %>%
st_as_sf() %>%
ggplot() +
geom_sf(aes(fill = access_retail_20), col = NA) +
scale_fill_viridis_c() +
labs(
title = 'Accessibility to retail points in Manchester by public transport within 20 minutes',
subtitle = 'Contains retail points larger than 280 m2',
fill = 'Retail points'
) +
theme_void()
```
## Citation
If you use this package, please cite as following:
* Verduzco Torres, J. R., & McArthur, D. P. (2024). Public transport accessibility indicators to urban and regional services in Great Britain. Scientific Data, 11(1), Article 1. https://doi.org/10.1038/s41597-023-02890-w
* Verduzco Torres, J. R. (2023). AccessUK (v0.0.1-alpha) [R]. University of Glasgow. https://github.com/urbanbigdatacentre/AccessUK
## Related resources and projects
* DuckDB - <https://duckdb.org/>
* Public transport accessibility indicators (PTAI) in Great Britain repo - <https://github.com/urbanbigdatacentre/access_uk_open>
* `accessibility` R package - <https://github.com/ipeaGIT/accessibility>
## References
1. Verduzco Torres, J. R., & McArthur, D. (2022). Public Transport Accessibility Indicators for Great Britain [dataset]. Zenodo. https://doi.org/10.5281/zenodo.8037156
2. Verduzco Torres, J. R., & McArthur, D. P. (2024). Public transport accessibility indicators to urban and regional services in Great Britain. Scientific Data, 11(1), Article 1. https://doi.org/10.1038/s41597-023-02890-w