Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare DfT traffic count data with DfT coronavirus stats for cycling #72

Open
Robinlovelace opened this issue Dec 17, 2020 · 0 comments

Comments

@Robinlovelace
Copy link
Contributor

Robinlovelace commented Dec 17, 2020

Will be an interesting comparison. Here's the DfT coronavirus data:

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)

u = "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/942559/COVID-19-transport-use-statistics.ods"
f = basename(u)
download.file(u, f)
d_original = tibble::tibble(readODS::read_ods(f, skip = 6))
names(d_original) = gsub(pattern = "\\d", replacement = "", x = names(d_original))
d = janitor::clean_names(d_original)
d = d[nchar(d[[1]]) == 10, ]
d$date = lubridate::dmy(d$date_weekends_and_bank_holidays_in_grey)
d = d %>% select(-(cars:heavy_goods_vehicles))

d = d %>%
  mutate(across(all_motor_vehicles:cycling, as.numeric))
#> Warning: Problem with `mutate()` input `..1`.
#> ℹ NAs introduced by coercion
#> ℹ Input `..1` is `across(all_motor_vehicles:cycling, as.numeric)`.
#> Warning in fn(col, ...): NAs introduced by coercion
#> Warning: Problem with `mutate()` input `..1`.
#> ℹ NAs introduced by coercion
#> ℹ Input `..1` is `across(all_motor_vehicles:cycling, as.numeric)`.
#> Warning in fn(col, ...): NAs introduced by coercion
#> Warning: Problem with `mutate()` input `..1`.
#> ℹ NAs introduced by coercion
#> ℹ Input `..1` is `across(all_motor_vehicles:cycling, as.numeric)`.
#> Warning in fn(col, ...): NAs introduced by coercion
#> Warning: Problem with `mutate()` input `..1`.
#> ℹ NAs introduced by coercion
#> ℹ Input `..1` is `across(all_motor_vehicles:cycling, as.numeric)`.
#> Warning in fn(col, ...): NAs introduced by coercion
  # mutate(across(cars:cycling, as.numeric))
# summary(d)

droll = d %>%
  mutate(across(all_motor_vehicles:cycling, zoo::rollmean, k = 30, align = "right", fill = NA))
  # mutate(across(cars:cycling, zoo::rollmean, k = 30, align = "right", fill = NA))
# d
# nrow(d)
d_long = tidyr::pivot_longer(d, cols = all_motor_vehicles:cycling)
droll_long = tidyr::pivot_longer(droll, cols = all_motor_vehicles:cycling)
d_long$date = as.Date(d_long$date)
droll_long$date = as.Date(droll_long$date)
g = ggplot(droll_long) +
  geom_line(aes(date, value, colour = name), size = 1.3) +
  geom_line(aes(date, value, colour = name), alpha = 0.3, data = d_long) +
  scale_y_continuous(labels = scales::percent) +
  theme_bw()
g
#> Warning: Removed 233 row(s) containing missing values (geom_path).
#> Warning: Removed 51 row(s) containing missing values (geom_path).

Created on 2020-12-17 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant