-
Notifications
You must be signed in to change notification settings - Fork 47
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
Coursework questions #28
Comments
Robin, |
I just mean what % of people walk. Reproducible example showing how the walking level, based on 2011 Census data from the UK, varies across West Yorkshire: library(pct)
library(tmap)
zones = pct::get_pct_zones(region = "west-yorkshire")
zones$percent_walk = zones$foot / zones$all * 100
tm_shape(zones) +
tm_polygons("percent_walk")
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0 Created on 2020-03-23 by the reprex package (v0.3.0) |
I want to produce a map from pct_zones regarding london boroughs, rather than the 'msoa' level that is automatically provided. This involves merging polygons based on 'lad_name'. |
Hi @Emily181 apologies for the slow reply. Happy to say I certainly can help here. |
Here is some starter code that gets data at the borough level. @Emily181 if you can provide some additional reproducible examples that could help answer the question but this should be a good starting point. Any further questions very welcome. # Aim: get data from PCT for London boroughs
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
library(tidyverse)
# get zones/centroids data ------------------------------------------------
region_name = "london"
zones_msoa = pct::get_pct_zones(region = region_name)
centroids_msoa = pct::get_pct_centroids(region = region_name)
centroids_lsoa = pct::get_pct_centroids(region = region_name, geography = "lsoa") # in case lsoa data would be useful
names(zones_msoa)
#> [1] "geo_code" "geo_name"
#> [3] "lad11cd" "lad_name"
#> [5] "all" "bicycle"
#> [7] "foot" "car_driver"
#> [9] "car_passenger" "motorbike"
#> [11] "train_tube" "bus"
#> [13] "taxi_other" "govtarget_slc"
#> [15] "govtarget_sic" "govtarget_slw"
#> [17] "govtarget_siw" "govtarget_sld"
#> [19] "govtarget_sid" "govtarget_slp"
#> [21] "govtarget_sip" "govtarget_slm"
#> [23] "govtarget_sim" "govtarget_slpt"
#> [25] "govtarget_sipt" "govnearmkt_slc"
#> [27] "govnearmkt_sic" "govnearmkt_slw"
#> [29] "govnearmkt_siw" "govnearmkt_sld"
#> [31] "govnearmkt_sid" "govnearmkt_slp"
#> [33] "govnearmkt_sip" "govnearmkt_slm"
#> [35] "govnearmkt_sim" "govnearmkt_slpt"
#> [37] "govnearmkt_sipt" "gendereq_slc"
#> [39] "gendereq_sic" "gendereq_slw"
#> [41] "gendereq_siw" "gendereq_sld"
#> [43] "gendereq_sid" "gendereq_slp"
#> [45] "gendereq_sip" "gendereq_slm"
#> [47] "gendereq_sim" "gendereq_slpt"
#> [49] "gendereq_sipt" "dutch_slc"
#> [51] "dutch_sic" "dutch_slw"
#> [53] "dutch_siw" "dutch_sld"
#> [55] "dutch_sid" "dutch_slp"
#> [57] "dutch_sip" "dutch_slm"
#> [59] "dutch_sim" "dutch_slpt"
#> [61] "dutch_sipt" "ebike_slc"
#> [63] "ebike_sic" "ebike_slw"
#> [65] "ebike_siw" "ebike_sld"
#> [67] "ebike_sid" "ebike_slp"
#> [69] "ebike_sip" "ebike_slm"
#> [71] "ebike_sim" "ebike_slpt"
#> [73] "ebike_sipt" "base_slcyclehours"
#> [75] "govtarget_sicyclehours" "govnearmkt_sicyclehours"
#> [77] "gendereq_sicyclehours" "dutch_sicyclehours"
#> [79] "ebike_sicyclehours" "base_sldeath"
#> [81] "base_slyll" "base_slvalueyll"
#> [83] "base_slsickdays" "base_slvaluesick"
#> [85] "base_slvaluecomb" "govtarget_sideath"
#> [87] "govtarget_siyll" "govtarget_sivalueyll"
#> [89] "govtarget_sisickdays" "govtarget_sivaluesick"
#> [91] "govtarget_sivaluecomb" "govnearmkt_sideath"
#> [93] "govnearmkt_siyll" "govnearmkt_sivalueyll"
#> [95] "govnearmkt_sisickdays" "govnearmkt_sivaluesick"
#> [97] "govnearmkt_sivaluecomb" "gendereq_sideath"
#> [99] "gendereq_siyll" "gendereq_sivalueyll"
#> [101] "gendereq_sisickdays" "gendereq_sivaluesick"
#> [103] "gendereq_sivaluecomb" "dutch_sideath"
#> [105] "dutch_siyll" "dutch_sivalueyll"
#> [107] "dutch_sisickdays" "dutch_sivaluesick"
#> [109] "dutch_sivaluecomb" "ebike_sideath"
#> [111] "ebike_siyll" "ebike_sivalueyll"
#> [113] "ebike_sisickdays" "ebike_sivaluesick"
#> [115] "ebike_sivaluecomb" "base_slcarkm"
#> [117] "base_slco2" "govtarget_sicarkm"
#> [119] "govtarget_sico2" "govnearmkt_sicarkm"
#> [121] "govnearmkt_sico2" "gendereq_sicarkm"
#> [123] "gendereq_sico2" "dutch_sicarkm"
#> [125] "dutch_sico2" "ebike_sicarkm"
#> [127] "ebike_sico2" "perc_rf_dist_u10km"
#> [129] "avslope_perc_u10km" "geometry"
plot(zones_msoa["lad_name"]) # looks like boroughs!
# create borough regions --------------------------------------------------
borough_summaries = zones_msoa %>%
group_by(lad_name) %>%
summarise(
all = sum(all),
bicycle = sum(bicycle),
percent_cycle = sum(bicycle) / sum(all) * 100,
percent_wal = sum(foot) / sum(all) * 100
)
plot(borough_summaries) Created on 2020-03-31 by the reprex package (v0.3.0) Session infodevtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 3.6.3 (2020-02-29)
#> os Ubuntu 18.04.4 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language en_GB:en
#> collate en_GB.UTF-8
#> ctype en_GB.UTF-8
#> tz Europe/London
#> date 2020-03-31
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [2] CRAN (R 3.6.0)
#> backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.1)
#> broom 0.5.5 2020-02-29 [1] CRAN (R 3.6.2)
#> callr 3.4.2 2020-02-12 [1] CRAN (R 3.6.2)
#> cellranger 1.1.0 2016-07-27 [3] CRAN (R 3.5.0)
#> class 7.3-16 2020-03-25 [2] CRAN (R 3.6.3)
#> classInt 0.4-3 2020-03-24 [1] Github (r-spatial/classInt@036a85d)
#> cli 2.0.2 2020-02-28 [1] CRAN (R 3.6.2)
#> colorspace 1.4-1 2019-03-18 [2] CRAN (R 3.5.3)
#> crayon 1.3.4 2017-09-16 [2] standard (@1.3.4)
#> curl 4.3 2019-12-02 [2] CRAN (R 3.6.2)
#> DBI 1.1.0 2019-12-15 [2] CRAN (R 3.6.2)
#> dbplyr 1.4.2 2019-06-17 [3] CRAN (R 3.6.0)
#> desc 1.2.0 2018-05-01 [2] standard (@1.2.0)
#> devtools 2.2.2 2020-02-17 [1] CRAN (R 3.6.2)
#> digest 0.6.25 2020-02-23 [1] CRAN (R 3.6.2)
#> dplyr * 0.8.5 2020-03-07 [1] CRAN (R 3.6.3)
#> e1071 1.7-3 2019-11-26 [2] CRAN (R 3.6.1)
#> ellipsis 0.3.0 2019-09-20 [3] CRAN (R 3.6.1)
#> evaluate 0.14 2019-05-28 [2] CRAN (R 3.6.0)
#> fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.2)
#> forcats * 0.5.0 2020-03-01 [3] CRAN (R 3.6.3)
#> fs 1.3.2 2020-03-05 [2] CRAN (R 3.6.3)
#> generics 0.0.2 2018-11-29 [3] CRAN (R 3.5.1)
#> ggplot2 * 3.3.0 2020-03-05 [1] CRAN (R 3.6.3)
#> glue 1.3.2 2020-03-12 [2] CRAN (R 3.6.3)
#> gtable 0.3.0 2019-03-25 [3] CRAN (R 3.5.3)
#> haven 2.2.0 2019-11-08 [1] CRAN (R 3.6.1)
#> highr 0.8 2019-03-20 [3] CRAN (R 3.5.3)
#> hms 0.5.3 2020-01-08 [1] CRAN (R 3.6.2)
#> htmltools 0.4.0.9003 2020-03-25 [1] Github (rstudio/htmltools@1a35072)
#> httr 1.4.1 2019-08-05 [2] CRAN (R 3.6.1)
#> jsonlite 1.6.1 2020-02-02 [1] CRAN (R 3.6.2)
#> KernSmooth 2.23-16 2019-10-15 [4] CRAN (R 3.6.1)
#> knitr 1.28 2020-02-06 [1] CRAN (R 3.6.2)
#> lattice 0.20-40 2020-02-19 [2] CRAN (R 3.6.2)
#> lifecycle 0.2.0.9000 2020-03-16 [1] Github (r-lib/lifecycle@355dcba)
#> lubridate 1.7.4 2018-04-11 [2] CRAN (R 3.5.3)
#> magrittr 1.5 2014-11-22 [2] CRAN (R 3.5.2)
#> memoise 1.1.0 2017-04-21 [3] CRAN (R 3.5.0)
#> mime 0.9 2020-02-04 [1] CRAN (R 3.6.2)
#> modelr 0.1.6 2020-02-22 [3] CRAN (R 3.6.3)
#> munsell 0.5.0 2018-06-12 [3] CRAN (R 3.5.0)
#> nlme 3.1-145 2020-03-04 [4] CRAN (R 3.6.3)
#> pct 0.4.0 2020-03-09 [1] Github (itsleeds/pct@3dc18e1)
#> pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.2)
#> pkgbuild 1.0.6 2019-10-09 [2] CRAN (R 3.6.1)
#> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 3.6.1)
#> pkgload 1.0.2 2018-10-29 [3] CRAN (R 3.5.1)
#> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.2)
#> processx 3.4.2 2020-02-09 [2] CRAN (R 3.6.2)
#> ps 1.3.2 2020-02-13 [1] CRAN (R 3.6.3)
#> purrr * 0.3.3 2019-10-18 [1] CRAN (R 3.6.1)
#> R6 2.4.1 2019-11-12 [2] CRAN (R 3.6.1)
#> Rcpp 1.0.4 2020-03-17 [1] CRAN (R 3.6.3)
#> readr * 1.3.1 2018-12-21 [2] CRAN (R 3.5.3)
#> readxl 1.3.1 2019-03-13 [3] CRAN (R 3.5.3)
#> remotes 2.1.1 2020-02-15 [1] CRAN (R 3.6.2)
#> reprex 0.3.0 2019-05-16 [3] CRAN (R 3.6.0)
#> rlang 0.4.5.9000 2020-03-25 [1] Github (r-lib/rlang@a90b04b)
#> rmarkdown 2.1.1 2020-03-25 [1] Github (rstudio/rmarkdown@947b872)
#> rprojroot 1.3-2 2018-01-03 [2] CRAN (R 3.5.3)
#> rvest 0.3.5 2019-11-08 [3] CRAN (R 3.6.1)
#> scales 1.1.0 2019-11-18 [1] CRAN (R 3.6.1)
#> sessioninfo 1.1.1 2018-11-05 [3] CRAN (R 3.5.1)
#> sf * 0.9-1 2020-03-27 [1] Github (r-spatial/sf@69c8d42)
#> stringi 1.4.6 2020-02-17 [1] CRAN (R 3.6.2)
#> stringr * 1.4.0 2019-02-10 [2] standard (@1.4.0)
#> testthat 2.3.2 2020-03-02 [1] CRAN (R 3.6.3)
#> tibble * 2.99.99.9014 2020-03-27 [1] Github (tidyverse/tibble@3a050ab)
#> tidyr * 1.0.2 2020-01-24 [3] CRAN (R 3.6.2)
#> tidyselect 1.0.0 2020-01-27 [1] CRAN (R 3.6.2)
#> tidyverse * 1.3.0 2019-11-21 [3] CRAN (R 3.6.1)
#> units 0.6-6 2020-03-16 [1] CRAN (R 3.6.3)
#> usethis 1.5.1.9000 2020-03-27 [1] Github (r-lib/usethis@a2c118f)
#> vctrs 0.2.99.9010 2020-03-27 [1] Github (r-lib/vctrs@ce16d1c)
#> withr 2.1.2 2018-03-15 [2] CRAN (R 3.5.3)
#> xfun 0.12 2020-01-13 [1] CRAN (R 3.6.2)
#> xml2 1.2.5 2020-03-11 [3] CRAN (R 3.6.3)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.2)
#>
#> [1] /home/robin/R/x86_64-pc-linux-gnu-library/3.6
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library |
Thank you. I also haven't been able to find documentation on what many of the variables in 'zones_msoa' actually describe? Is there somewhere that does? |
Very good question that reveals a limitation of the PCT. See here for the 'codebooks': https://github.com/npct/pct-shiny/blob/master/regions_www/www/static/02_codebooks/commute/z_codebook.csv |
Hi @Joe618 yes you can use those variables. |
See here for descriptions of those variables: https://github.com/npct/pct-shiny/blob/master/regions_www/www/static/02_codebooks/commute/od_l_rf_codebook.csv |
See below for a reproducible 'starter for 10' for analysing walking data. Note: distance is important! # install.packages("pct")
# get data
l = pct::get_pct_lines("west-yorkshire")
names(l)
#> [1] "id" "geo_code1"
#> [3] "geo_code2" "geo_name1"
#> [5] "geo_name2" "lad11cd1"
#> [7] "lad11cd2" "lad_name1"
#> [9] "lad_name2" "all"
#> [11] "bicycle" "foot"
#> [13] "car_driver" "car_passenger"
#> [15] "motorbike" "train_tube"
#> [17] "bus" "taxi_other"
#> [19] "govtarget_slc" "govtarget_sic"
#> [21] "govtarget_slw" "govtarget_siw"
#> [23] "govtarget_sld" "govtarget_sid"
#> [25] "govtarget_slp" "govtarget_sip"
#> [27] "govtarget_slm" "govtarget_sim"
#> [29] "govtarget_slpt" "govtarget_sipt"
#> [31] "govnearmkt_slc" "govnearmkt_sic"
#> [33] "govnearmkt_slw" "govnearmkt_siw"
#> [35] "govnearmkt_sld" "govnearmkt_sid"
#> [37] "govnearmkt_slp" "govnearmkt_sip"
#> [39] "govnearmkt_slm" "govnearmkt_sim"
#> [41] "govnearmkt_slpt" "govnearmkt_sipt"
#> [43] "gendereq_slc" "gendereq_sic"
#> [45] "gendereq_slw" "gendereq_siw"
#> [47] "gendereq_sld" "gendereq_sid"
#> [49] "gendereq_slp" "gendereq_sip"
#> [51] "gendereq_slm" "gendereq_sim"
#> [53] "gendereq_slpt" "gendereq_sipt"
#> [55] "dutch_slc" "dutch_sic"
#> [57] "dutch_slw" "dutch_siw"
#> [59] "dutch_sld" "dutch_sid"
#> [61] "dutch_slp" "dutch_sip"
#> [63] "dutch_slm" "dutch_sim"
#> [65] "dutch_slpt" "dutch_sipt"
#> [67] "ebike_slc" "ebike_sic"
#> [69] "ebike_slw" "ebike_siw"
#> [71] "ebike_sld" "ebike_sid"
#> [73] "ebike_slp" "ebike_sip"
#> [75] "ebike_slm" "ebike_sim"
#> [77] "ebike_slpt" "ebike_sipt"
#> [79] "base_slcyclehours" "govtarget_sicyclehours"
#> [81] "govnearmkt_sicyclehours" "gendereq_sicyclehours"
#> [83] "dutch_sicyclehours" "ebike_sicyclehours"
#> [85] "base_sldeath" "base_slyll"
#> [87] "base_slvalueyll" "base_slsickdays"
#> [89] "base_slvaluesick" "base_slvaluecomb"
#> [91] "govtarget_sideath" "govtarget_siyll"
#> [93] "govtarget_sivalueyll" "govtarget_sisickdays"
#> [95] "govtarget_sivaluesick" "govtarget_sivaluecomb"
#> [97] "govnearmkt_sideath" "govnearmkt_siyll"
#> [99] "govnearmkt_sivalueyll" "govnearmkt_sisickdays"
#> [101] "govnearmkt_sivaluesick" "govnearmkt_sivaluecomb"
#> [103] "gendereq_sideath" "gendereq_siyll"
#> [105] "gendereq_sivalueyll" "gendereq_sisickdays"
#> [107] "gendereq_sivaluesick" "gendereq_sivaluecomb"
#> [109] "dutch_sideath" "dutch_siyll"
#> [111] "dutch_sivalueyll" "dutch_sisickdays"
#> [113] "dutch_sivaluesick" "dutch_sivaluecomb"
#> [115] "ebike_sideath" "ebike_siyll"
#> [117] "ebike_sivalueyll" "ebike_sisickdays"
#> [119] "ebike_sivaluesick" "ebike_sivaluecomb"
#> [121] "base_slcarkm" "base_slco2"
#> [123] "govtarget_sicarkm" "govtarget_sico2"
#> [125] "govnearmkt_sicarkm" "govnearmkt_sico2"
#> [127] "gendereq_sicarkm" "gendereq_sico2"
#> [129] "dutch_sicarkm" "dutch_sico2"
#> [131] "ebike_sicarkm" "ebike_sico2"
#> [133] "e_dist_km" "rf_dist_km"
#> [135] "rq_dist_km" "dist_rf_e"
#> [137] "dist_rq_rf" "rf_avslope_perc"
#> [139] "rq_avslope_perc" "rf_time_min"
#> [141] "rq_time_min" "geometry"
l$percent_walking = l$foot / l$all
summary(l$percent_walking)
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 0.00000 0.00000 0.01087 0.04619 0.06154 0.77575
plot(l$rf_dist_km, l$percent_walking) # with ggplot2
library(tidyverse)
ggplot(l, aes(rf_dist_km, percent_walking)) +
geom_point() +
geom_smooth()
#> `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")' # geographic plot
l_short = l %>%
filter(rf_dist_km < 5)
library(tmap)
tm_shape(l_short) +
tm_lines("percent_walking", palette = "Blues")
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0 Created on 2020-05-15 by the reprex package (v0.3.0) |
Does that answer your question @Joe618 ? Thanks for asking. |
Hi Robin, Could you explain what the meanings of 'Straight line', Fast route', 'Quiet route' are respectively? because I am not familiar with the traffic situation of UK. Thanks in advance. |
Does that help? |
Hi Robin, This question aims to 'How do walking levels relate to pedestrian safety?' Now I would like to combine the desire lines of pct package and the crash data of stats19 package, so could you tell me how to overlay the desire lines to the crash data? because I want to see the relationship between walking levels and crashes. Thanks in advance. |
This is an interesting research question @Joe618. There are various options, one of which could be to get an estimate of walking and cycling levels at high geographic resolution, e.g. from the Note: initiative and creativity are encouraged. |
Hi Robin, Could you explain more details about how to get an estimate of walking and cycling levels at high geographic resolution from the pct package? Thanks in advance. |
If you say using machine learning to estimate the correlations between walking and cycling level, I has used this method to find what explanatory variables best predict the level of walking. So I am confused how to get an estimate of walking and cycling levels. |
The |
Actually, I have completed predictions to walking levels with explanatory variables. |
Have you tried downloading route network data @Joe618 ? Ways to do that are documented here: https://itsleeds.github.io/pct/reference/get_pct_rnet.html |
The results from the Propensity to Cycle Tool provide provide results for cycling and not walking I'm afraid. I suggest either focussing on cycling trying to find data on walking. As shown above you get data on walking at the OD and route level from the pct package. You could use the function |
Hi Robin, How do I mark or get the route level from the pct package ? |
Hi @Joe618 see here for information on getting OD data: https://itsleeds.github.io/pct/reference/get_od.html And here for information on route data - note it's the 'cycling route' but is not far from the walking route in many cases: https://itsleeds.github.io/pct/reference/get_pct_routes_fast.html Please check online and in package documentation before asking next time. |
Hi @Joe618, no sorry I cannot provide further teaching on this. Best of luck writing-up the coursework. |
Could I know the reasons? because I suppose the coursework just is the general assignment rather than examinations😂. |
I just would like to know how to overlay the crahes_iow to roads_wgs. It is a question of R programming. Could you help me ? |
The coursework submissions will be marked and will determine your marks for the module, so in a way it is an examination. Closing for now but if there are follow-up questions feel free to let me know. |
Any issues with the coursework? Feel free to let me know here!
The text was updated successfully, but these errors were encountered: