From 86b6f71a3dc3b8d287b2d7ad0760bb7f1282fbd1 Mon Sep 17 00:00:00 2001 From: CatReid Date: Tue, 17 Dec 2024 09:39:04 +0000 Subject: [PATCH] First draft completed - air-pollution First draft completed - air-pollution. Code updated from original script, styled and rendered. --- R/data.R | 16 +++++++++++ data-raw/healthy-places/air-pollution.R | 34 +++++++++++++++--------- data/places_air_pollution.rda | Bin 0 -> 380 bytes man/places_air_pollution.Rd | 27 +++++++++++++++++++ metadata.md | 2 +- 5 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 data/places_air_pollution.rda create mode 100644 man/places_air_pollution.Rd diff --git a/R/data.R b/R/data.R index 327711a..a8336fb 100644 --- a/R/data.R +++ b/R/data.R @@ -267,6 +267,22 @@ #' @source \url{https://www.nisra.gov.uk/publications/census-2021-main-statistics-health-disability-and-unpaid-care-tables} "people_mental_health" +#' Air pollution (2019) +#' +#' A dataset containing population-weighted annual mean PM2.5 data for 2019, by +#' Northern Irish Council Area. Uses the anthropogenic component. +#' +#' @format A data frame with 11 rows and 3 variables: +#' \describe{ +#' \item{ltla24_code}{Local Authority Code} +#' \item{air_pollution_weighted}{Population-weighted annual mean PM2.5} +#' \item{year}{Year} +#' +#' ... +#' } +#' @source \url{https://uk-air.defra.gov.uk/data/pcm-data} +"places_air_pollution" + #' Rates of Personal Crime per 1,000 (2017) #' #' A dataset containing statistics on 'personal crime' per 1,000 people in diff --git a/data-raw/healthy-places/air-pollution.R b/data-raw/healthy-places/air-pollution.R index a9bf171..9b28593 100644 --- a/data-raw/healthy-places/air-pollution.R +++ b/data-raw/healthy-places/air-pollution.R @@ -1,13 +1,15 @@ +# ---- Load packages ---- library(tidyverse) library(geographr) -# Lookup -lookup <- - boundaries_lad |> - select(-geometry) |> - st_drop_geometry() |> - filter(str_detect(lad_code, "^N")) +# ---- Get data ---- +# LA Codes +ltla_lookup <- lookup_ltla_ltla |> + filter(str_detect(ltla23_code, "N")) |> + select(ltla23_code, ltla23_name) + +# Air Pollution # Source: https://uk-air.defra.gov.uk/data/pcm-data air_pollution_raw <- read_csv( @@ -19,14 +21,20 @@ air_pollution_raw <- air_pollution <- air_pollution_raw |> select( - lad_name = `Local Authority`, + ltla23_name = `Local Authority`, air_pollution_weighted = `PM2.5 2019 (anthropogenic)` ) -# Join -air_pollution <- - lookup |> - left_join(air_pollution, by = "lad_name") |> - select(-lad_name) +# Join datasets +places_air_pollution <- + ltla_lookup |> + left_join(air_pollution, by = "ltla23_name") |> + select( + ltla24_code = ltla23_code, + air_pollution_weighted, + -ltla23_name + ) |> + mutate(year = "2019") -write_rds(air_pollution, "data/vulnerability/health-inequalities/northern-ireland/healthy-places/air-pollution.rds") \ No newline at end of file +# ---- Save output to data/ folder ---- +usethis::use_data(places_air_pollution, overwrite = TRUE) diff --git a/data/places_air_pollution.rda b/data/places_air_pollution.rda new file mode 100644 index 0000000000000000000000000000000000000000..ac81542ca8bba3b7a1552d2dbb715892dafbf4c1 GIT binary patch literal 380 zcmV-?0fYWRT4*^jL0KkKS;~#l<^Ta0|Ns9x|APimf8kU?5K_PI-lIT703ZNCg5iiM z5CuVD0x7To7+Mh&13(P`00003KmarV20+p3Xd?SoPzEYR+C@~3$k;OrRErOjevv8UfzcR>5P)igAlgK4BI|#;N+#BJ zR$n#5Ag^l9Q?nB7ik8CbWTC2ngcQYOz<_}Bn7oCMZ`92!HStfRh^rVJ2qFb