Skip to content

Added new population estimates for Scotland and NI #12

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ NULL
#' @source \url{https://ons.gov.uk/}
"population19_utla20"


#' Population estimates for Data Zones in Scotland (2020 estimates with 2011 codes)
#'
#' A data set containing 2020 population estimates by age and sex for Data Zones in Scotland.
Expand All @@ -271,6 +270,21 @@ NULL
#' @source \url{https://www.opendata.nhs.scot/}
"population20_dz11"

#' Population estimates for Data Zones in Scotland (2021 estimates with 2011 codes)
#'
#' A data set containing 2021 population estimates by age and sex for Data Zones in Scotland.
#'
#' @format A data frame of class "tbl" with 20,928 rows and 94 variables:
#' \describe{
#' \item{dz11_code}{Data Zone code}
#' \item{total_population}{Total number of people living in each DZ}
#' \item{sex}{'Female', 'Male' or 'All'}
#' \item{`0`:`90+`}{Number of people in each single age group}
#' ...
#' }
#' @source \url{https://www.opendata.nhs.scot/}
"population21_dz11"

#' Population estimates for LSOAs in England and Wales (mid-2020 estimates with 2011 codes)
#'
#' A data set containing mid-2020 population estimates for Lower Layer Super Output Areas in England and Wales.
Expand Down Expand Up @@ -364,6 +378,19 @@ NULL
#' @source \url{https://ons.gov.uk/}
"population20_utla20"

#' Population estimates for SOAs in Northern Ireland (mid-2020 estimates with 2011 codes)
#'
#' A data set containing mid-2020 population estimates for Super Output Areas in Northern Ireland.
#'
#' @format A data frame of class "tbl" with 4,537 rows and 2 variables:
#' \describe{
#' \item{soa11_code}{SOA code}
#' \item{total_population}{Total number of people living in each SOA}
#' ...
#' }
#' @source \url{https://nisra.gov.uk/}
"population20_soa11"

#' Population in UK countries, as of Census 2021
#'
#' A data sets containing Census 2021 population counts for each UK nation.
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
28 changes: 28 additions & 0 deletions data-raw/population20_soa11.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ---- Load ----
library(tidyverse)
library(devtools)
library(compositr)
library(readxl)

# Load package
load_all(".")

# Set query url
query_url <-
query_urls |>
filter(id == "estimates20_soa11") |>
pull(query)

tf <- download_file(query_url, ".xlsx")

soa_pop <- read_excel(tf, sheet = "Flat")

population20_soa11 <-
soa_pop |>
filter(Year == max(Year)) |>
filter(Area == "Small Areas") |>

select(soa11_code = Area_Code, total_population = MYE)

# Save output to data/ folder
usethis::use_data(population20_soa11, overwrite = TRUE)
38 changes: 38 additions & 0 deletions data-raw/population21_dz11.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# ---- Load ----
library(tidyverse)
library(devtools)

# Load package
load_all(".")

# Set query url
query_url <-
query_urls |>
filter(id == "estimates21_dz11") |>
pull(query)

dz_pop <- read_csv(query_url)

population_dz <-
dz_pop |>

# Keep year 2021 and don't include Scotland totals
filter(Year == "2021" & DataZone != "S92000003") |>

# Select and rename vars
select(
dz11_code = `DataZone`,
`total_population` = AllAges,
sex = Sex,
Age0:Age90plus
) |>

# Rename single years of age columns in line with England and Wales' naming
rename_with(~ str_remove(.x, "Age"), starts_with("Age")) |>
rename(`90+` = `90plus`)

# Rename
population21_dz11 <- population_dz

# Save output to data/ folder
usethis::use_data(population21_dz11, overwrite = TRUE)
2 changes: 2 additions & 0 deletions data-raw/query_urls.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ query_urls <-
"population", "estimates19_utla19", "24.06.20", "OGLv3", "https://www.ons.gov.uk/file?uri=%2fpeoplepopulationandcommunity%2fpopulationandmigration%2fpopulationestimates%2fdatasets%2fpopulationestimatesforukenglandandwalesscotlandandnorthernireland%2fmid2019april2019localauthoritydistrictcodes/ukmidyearestimates20192019ladcodes.xls", "https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland",
"population", "estimates19_utla20", "24.06.20", "OGLv3", "https://www.ons.gov.uk/file?uri=/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland/mid2019april2020localauthoritydistrictcodes/ukmidyearestimates20192020ladcodes.xls", "https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland",
"population", "estimates20_dz11", "11.10.21", "OGLv3", "https://www.opendata.nhs.scot/datastore/dump/c505f490-c201-44bd-abd1-1bd7a64285ee?bom=True", "https://www.opendata.nhs.scot/dataset/population-estimates/resource/c505f490-c201-44bd-abd1-1bd7a64285ee",
"population", "estimates21_dz11", "31.07.23", "OGLv3", "https://www.opendata.nhs.scot/dataset/7f010430-6ce1-4813-b25c-f7f335bdc4dc/resource/c505f490-c201-44bd-abd1-1bd7a64285ee/download/dz2011-pop-est_09092022.csv", "https://www.opendata.nhs.scot/dataset/population-estimates",
"population", "estimates20_lsoa11", "16.109.21", "OGLv3", "https://www.ons.gov.uk/file?uri=%2fpeoplepopulationandcommunity%2fpopulationandmigration%2fpopulationestimates%2fdatasets%2flowersuperoutputareamidyearpopulationestimates%2fmid2020sape23dt2/sape23dt2mid2020lsoasyoaestimatesunformatted.xlsx", "https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/lowersuperoutputareamidyearpopulationestimates",
"population", "estimates20_ltla20", "25.06.21", "OGLv3", "https://www.ons.gov.uk/file?uri=%2fpeoplepopulationandcommunity%2fpopulationandmigration%2fpopulationestimates%2fdatasets%2fpopulationestimatesforukenglandandwalesscotlandandnorthernireland%2fmid2020/ukpopestimatesmid2020on2020geography.xls", "https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland",
"population", "estimates20_ltla21", "25.06.21", "OGLv3", "https://www.ons.gov.uk/file?uri=%2fpeoplepopulationandcommunity%2fpopulationandmigration%2fpopulationestimates%2fdatasets%2fpopulationestimatesforukenglandandwalesscotlandandnorthernireland%2fmid2020/ukpopestimatesmid2020on2021geography.xls", "https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland",
"population", "estimates20_msoa11", "16.109.21", "OGLv3", "https://www.ons.gov.uk/file?uri=%2fpeoplepopulationandcommunity%2fpopulationandmigration%2fpopulationestimates%2fdatasets%2fmiddlesuperoutputareamidyearpopulationestimates%2fmid2020sape23dt4/sape23dt4mid2020msoasyoaestimatesunformatted.xlsx", "https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/middlesuperoutputareamidyearpopulationestimates",
"population", "estimates20_utla20", "25.06.21", "OGLv3", "https://www.ons.gov.uk/file?uri=%2fpeoplepopulationandcommunity%2fpopulationandmigration%2fpopulationestimates%2fdatasets%2fpopulationestimatesforukenglandandwalesscotlandandnorthernireland%2fmid2020/ukpopestimatesmid2020on2021geography.xls", "https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland",
"population", "estimates20_soa11", "25.11.21", "OGL v3", "https://www.nisra.gov.uk/system/files/statistics/SAPE20-SA-Totals.xlsx", "https://www.nisra.gov.uk/publications/2020-mid-year-population-estimates-small-areas",
"population", "estimates21_ltla21_scot", "13.07.21", "OGLv3", "https://www.nrscotland.gov.uk/files//statistics/population-estimates/mid-21/mid-year-pop-est-21-data.xlsx", "https://www.nrscotland.gov.uk/statistics-and-data/statistics/statistics-by-theme/population/population-estimates/mid-year-population-estimates/mid-2021",
"population", "estimates_hb19", "15.07.22", "OGLv3", "https://www.opendata.nhs.scot/dataset/7f010430-6ce1-4813-b25c-f7f335bdc4dc/resource/27a72cc8-d6d8-430c-8b4f-3109a9ceadb1/download/hb2019_pop_est_15072022.csv", "https://www.opendata.nhs.scot/dataset/population-estimates/resource/27a72cc8-d6d8-430c-8b4f-3109a9ceadb1",

Expand Down
Binary file added data/population20_soa11.rda
Binary file not shown.
Binary file added data/population21_dz11.rda
Binary file not shown.
24 changes: 24 additions & 0 deletions man/population20_soa11.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions man/population21_dz11.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.