Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Robinlovelace/londonOD
https://github.com/Robinlovelace/londonOD
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/Robinlovelace/londonOD
- Owner: Robinlovelace
- Created: 2019-08-21T16:49:05.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-21T18:54:16.000Z (about 5 years ago)
- Last Synced: 2024-06-11T16:09:51.037Z (5 months ago)
- Size: 168 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
# londonODThe goal of londonOD is to showcase new OD data for London, uploaded in August 2019 to http://crowding.data.tfl.gov.uk/
This is a work in progress repo to get started.
We'll use these packages:
```{r, warning=FALSE, message=FALSE}
library(sf)
library(tmap)
library(dplyr)
library(stplanr)
```# Data cleaning
First step: clean the data.
```{r}
u = "http://crowding.data.tfl.gov.uk/NUMBAT/2018/Friday/2018FRI_OD_Network.xlsx"
if(!file.exists("network.xlsx"))
download.file(u, destfile = "network.xlsx")
d = readxl::read_excel("network.xlsx", 2, skip = 2)
stations_sample = unique(d$`Origin Station Name`)[1:10]
stations_sample_lnd = paste(stations_sample, "london")
# stations_sample_geo = ggmap::geocode(stations_sample_lnd)
stations_sample_geo = stplanr::geo_code(stations_sample_lnd[1])
ssg = sapply(stations_sample_lnd, FUN = stplanr::geo_code)
ssgt = t(ssg)
ssgt
ssgt_df = tibble::tibble(n = stations_sample, x = ssgt[, 1], y = ssgt[, 2])
names(ssgt_df)
d_sample = d[d$`Origin Station Name` %in% stations_sample &
d$`Destination Station Name` %in% stations_sample, ]
ssgt_sf = sf::st_as_sf(ssgt_df, coords = c("x", "y"), crs = 4326)
plot(ssgt_sf)
d_sample_renamed = d_sample %>% select(`Origin Station Name`, `Destination Station Name`, everything())
```# Convert to desire lines
```{r}
desire_lines = stplanr::od2line(flow = d_sample_renamed, ssgt_sf)
tmap_mode("view")
tm_shape(desire_lines) +
tm_lines(lwd = "Total", scale = 9)
```