geocompr icon indicating copy to clipboard operation
geocompr copied to clipboard

Imrovements to transport chapter

Open Robinlovelace opened this issue 2 years ago • 2 comments

  • [x] Fix error:
Quitting from lines 201-202 (13-transport.Rmd) 
Error in zones_attr$geo_code %in% bristol_zones$geo_code : 
  object 'zones_attr' not found
Calls: local ... eval_with_user_handlers -> eval -> eval -> summary -> %in%

Source: https://github.com/Robinlovelace/geocompr/runs/7383730658?check_suite_focus=true#step:4:8246

Split out from comments in https://github.com/Robinlovelace/geocompr/pull/826

  • [ ] code/13-transport-data-gen is not reproducible

  • [ ] Figure bristol contains red/green colors (not color blind friendly) -- can you improve it?

  • [ ] code/13-desire.R returns an error desire_lines_top5 = od2line(od_top5, zones_od) Error in UseMethod("od2line", object = zones) : no applicable method for 'od2line' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"

Will explore and fix if I can reproduce this, the code seems approximately right but may need upstream changes in stplanr related to recent deprecating of sp functionality. Eventually I want to use od as back-end powering this.

  • [ ] The routes figure could be improved (e.g., add manual legend, customize lwd, etc.)

  • [ ] The stations figure could be improved (e.g., add manual legend, customize lwd, etc.)

  • [ ] Improve exercises and add solutions

Robinlovelace avatar Jul 18 '22 05:07 Robinlovelace

Some minor bookkeeping from the read thru of the chapter. Managed to never take a transportation class in my civil engineering education, regretting it now!

  • reference issue in paragraph 1 in "Desire Lines" (lovelace_jittering_2022b?).
  • bristol_ttwa returns a warning about an old style crs. Recommend updating the data in spDataLarge unless there's an issue with backward compatability. Same for bristol_stations.
  • routes item in list in introduction has a broken reference.
  • first paragraph in "prioritizing new infrastructure" has a broken reference.
  • Paragraph beginning "Having created a scenario in which..." in "Route Networks" has a broken reference.
  • For the example in Route Networks, should the updated car_driver number be car_driver * (1 - uptake)? So bike trips increased by conversions and car trips becomes 1 - the converted fraction.

Lvulis avatar Jul 31 '22 21:07 Lvulis

Thanks for these additional points, will aim to act on them all in the not-too-distant future!

Robinlovelace avatar Aug 01 '22 09:08 Robinlovelace

Todo: remove all this output:

image

Robinlovelace avatar Aug 23 '22 10:08 Robinlovelace

Not perfect but the first map in C13 is now as follows. Any further suggestions/changes welcome @Nowosad. Longer term I'd like to improve the input datasets in spDataLarge but want to close this issue first.

image

Robinlovelace avatar Aug 28 '22 07:08 Robinlovelace

And rendered, before below. Map is too tall and definitely in need of some improvement in the previous version:

image

Robinlovelace avatar Aug 28 '22 07:08 Robinlovelace

And after:

image

Source: https://geocompr.robinlovelace.net/transport.html

Robinlovelace avatar Aug 28 '22 07:08 Robinlovelace

Nice WIP. I think that Figures 13.4, 13.5, and 13.6 have the biggest room for improvement...

Nowosad avatar Aug 28 '22 14:08 Nowosad

13.4 before:

image

Robinlovelace avatar Aug 28 '22 18:08 Robinlovelace

And after (also in #859 ):

image

Robinlovelace avatar Aug 28 '22 20:08 Robinlovelace

Heads-up @Nowosad another before/after:

image

After:

image

Robinlovelace avatar Aug 28 '22 21:08 Robinlovelace

Regarding 13-desire.R not being reproducible, it is now, I guess it was a temporary issue with an ephemeral version of stplanr:

# Aim: generate tmap figure representing desire lines

# load data if not already loaded:
if(!exists("desire_lines")) {
  library(sf)
  library(dplyr)
  library(spDataLarge)
  library(stplanr)
  library(tmap)     
  zones_attr = bristol_od |> 
    group_by(o) |> 
    summarize_if(is.numeric, sum) |> 
    dplyr::rename(geo_code = o)
  
  zones_joined = left_join(bristol_zones, zones_attr, by = "geo_code")
  
  zones_od = bristol_od |> 
    group_by(d) |> 
    summarize_if(is.numeric, sum) |> 
    dplyr::select(geo_code = d, all_dest = all) |> 
    inner_join(zones_joined, ., by = "geo_code") |> 
    st_as_sf()
  
  od_top5 = bristol_od |> 
    arrange(desc(all)) |> 
    top_n(5, wt = all)
  
  bristol_od$Active = (bristol_od$bicycle + bristol_od$foot) /
    bristol_od$all * 100
  
  od_intra = filter(bristol_od, o == d)
  od_inter = filter(bristol_od, o != d)
  desire_lines = od2line(od_inter, zones_od)
}
#> Linking to GEOS 3.10.2, GDAL 3.4.3, PROJ 8.2.0; sf_use_s2() is TRUE
#> 
#> 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
#> Creating centroids representing desire line start and end points.

# u_od = "https://user-images.githubusercontent.com/1825120/34081176-74fd39c8-e341-11e7-9f3e-b98807cb113b.png"
# knitr::include_graphics(u_od)
tmap_mode("plot")
#> tmap mode set to plotting
desire_lines_top5 = od2line(od_top5, zones_od)
#> Creating centroids representing desire line start and end points.
# tmaptools::palette_explorer()
tm_shape(desire_lines) +
  tm_lines(palette = "plasma", breaks = c(0, 5, 10, 20, 40, 100),
    lwd = "all",
    scale = 9,
    title.lwd = "Number of trips",
    alpha = 0.6,
    col = "Active",
    title = "Active travel (%)"
  ) +
  tm_shape(desire_lines_top5) +
  tm_lines(lwd = 5, col = "black", alpha = 0.7) +
  tm_scale_bar()
#> Legend labels were too wide. Therefore, legend.text.size has been set to 0.62. Increase legend.width (argument of tm_layout) to make the legend wider and therefore the labels larger.

Created on 2022-08-28 with reprex v2.0.2

Robinlovelace avatar Aug 28 '22 22:08 Robinlovelace

Final update on this today, all issues except for exercise improvements done I think. Heads-up @Lvulis your suggestions were v useful, you can see how I acted on them here: https://github.com/Robinlovelace/geocompr/pull/856

Robinlovelace avatar Aug 28 '22 22:08 Robinlovelace

Now the figures are much better! (One more thing to consider: adding explanation of the points to the map legends)

Nowosad avatar Aug 29 '22 06:08 Nowosad

One more thing to consider: adding explanation of the points to the map legends

Any idea how to do that with tmap (I tried but couldn't figure out how to get the custom palette working)? Here's the relevant code for the stations plot:

https://github.com/Robinlovelace/geocompr/blob/b9206d8b83f4b0ca5e1a1167601988d6de32bc26/13-transport.Rmd#L375-L414

And for the updated routes plot (would be good to have a legend just saying the black dot represents origins and destinations):

https://github.com/Robinlovelace/geocompr/blob/b9206d8b83f4b0ca5e1a1167601988d6de32bc26/13-transport.Rmd#L537-L553

Robinlovelace avatar Aug 29 '22 07:08 Robinlovelace

Fixed in #856

Robinlovelace avatar Aug 29 '22 14:08 Robinlovelace

Final update on this today, all issues except for exercise improvements done I think. Heads-up @Lvulis your suggestions were v useful, you can see how I acted on them here: #856

Thanks but those were minor things! The new figures look great.

Lvulis avatar Aug 29 '22 15:08 Lvulis