ITSLeeds / SSPA

Course materials for the ITS course TRAN5115, Sustainable Spatial Planning and Analysis (SSPA)
GNU General Public License v3.0
4 stars 2 forks source link

How to get IMD scores and transport data at the LSOA level for LAs? #2

Closed Robinlovelace closed 3 years ago

Robinlovelace commented 5 years ago

This code should do it for any LA.

Results for Richmondshire: https://github.com/ITSLeeds/SSPA/releases/download/V1.8.2/lsoa-imd-census-commute-transport-mode-data-Richmondshire.gpkg

Reproducible example:

# Aim: get IMD scores and mode split data at the LSOA level
# Works for any Local Authority in England:
la_name = "Richmondshire"

remotes::install_cran("snakecase")
#> Skipping install of 'snakecase' from a cran remote, the SHA1 (0.9.2) has not changed since last install.
#>   Use `force = TRUE` to force installation
remotes::install_github("itsleeds/pct", "national")
#> Skipping install of 'pct' from a github remote, the SHA1 (3fb93eab) has not changed since last install.
#>   Use `force = TRUE` to force installation
remotes::install_github("robinlovelace/ukboundaries")
#> Skipping install of 'ukboundaries' from a github remote, the SHA1 (1d162f0d) has not changed since last install.
#>   Use `force = TRUE` to force installation

u <- "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/467774/File_7_ID_2015_All_ranks__deciles_and_scores_for_the_Indices_of_Deprivation__and_population_denominators.csv"
d <- readr::read_csv(u)
#> Parsed with column specification:
#> cols(
#>   .default = col_double(),
#>   `LSOA code (2011)` = col_character(),
#>   `LSOA name (2011)` = col_character(),
#>   `Local Authority District code (2013)` = col_character(),
#>   `Local Authority District name (2013)` = col_character()
#> )
#> See spec(...) for full column specifications.
names(d) <- snakecase::to_snake_case(names(d))
names(d)[1] = "geo_code"

# pct package download
z <- pct::get_pct(layer = "z", geography = "lsoa", national = TRUE)
#> Loading required package: sp
zm <- dplyr::inner_join(z, d)
#> Joining, by = "geo_code"
# zm

zm_lds = zm[grepl(pattern = la_name, x = zm$geo_name), ]
plot(zm_lds[c("all", "bicycle", "car_driver", "index_of_multiple_deprivation_imd_score")])

mapview::mapview(zm_lds, zcol = "index_of_multiple_deprivation_imd_score")
filename = paste0("lsoa-imd-census-commute-transport-mode-data-", la_name, ".gpkg")
sf::write_sf(zm_lds, filename)
piggyback::pb_upload(filename)

Created on 2019-03-26 by the reprex package (v0.2.1)

Thanks to @eugenividal for helping with this.

Robinlovelace commented 5 years ago

And here's the code that generated it: https://github.com/ITSLeeds/SSPA/blob/master/examples/get-imd.R

Robinlovelace commented 4 years ago

Output at OA level

image