Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Robinlovelace/londonOD


https://github.com/Robinlovelace/londonOD

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
# londonOD

The 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)
```