Skip to content

Commit

Permalink
Add LSOA-level religion
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewgthomas committed Jul 10, 2024
1 parent 3078e34 commit 393709c
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Depends:
R (>= 2.10)
Imports:
Expand Down
17 changes: 17 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,20 @@ NULL
#' }
#' @source \url{https://www.nomisweb.co.uk/sources/census_2021_bulk}
"migration21_msoa21"

#' Religion data for England and Wales from the 2021 Census (MSOA)
#'
#' A data sets containing Census 2021 religion numbers and percentages for
#' each Lower Layer Super Output Area in England and Wales.
#'
#' @format A data frame of class "tbl" with 5 variables:
#' \describe{
#' \item{lsoa21_code}{LSOA code}
#' \item{total_residents}{Total number of residents in the LSOA}
#' \item{religion}{Religion}
#' \item{n}{Number of people in the religion}
#' \item{prop}{Percentage of people in the religion}
#' ...
#' }
#' @source \url{https://ons.gov.uk/}
"religion21_lsoa21"
Binary file modified R/sysdata.rda
Binary file not shown.
5 changes: 4 additions & 1 deletion data-raw/query_urls.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ query_urls <-
"population", "population20_oa11_l", "16.09.21", "OGLv3", "https://www.ons.gov.uk/file?uri=/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/censusoutputareaestimatesinthelondonregionofengland/mid2020sape23dt10a/sape23dt10amid2020coaunformattedsyoaestimateslondon.xlsx", "https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/bulletins/annualsmallareapopulationestimates/mid2020/relateddata?page=1",

# Proficiency in English
"proficiency", "proficiency21_msoa21", "29.11.22", "OGLv3", "https://www.nomisweb.co.uk/output/census/2021/census2021-ts029.zip", "https://www.nomisweb.co.uk/sources/census_2021_bulk"
"proficiency", "proficiency21_msoa21", "29.11.22", "OGLv3", "https://www.nomisweb.co.uk/output/census/2021/census2021-ts029.zip", "https://www.nomisweb.co.uk/sources/census_2021_bulk",

# Religion
"religion", "religion", "", "OGLv3", "https://www.nomisweb.co.uk/output/census/2021/census2021-ts030.zip", "https://www.nomisweb.co.uk/sources/census_2021_bulk"
)

usethis::use_data(query_urls, internal = TRUE, overwrite = TRUE)
37 changes: 37 additions & 0 deletions data-raw/religion21.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ---- Load libs ----
library(tidyverse)
library(geographr)
library(devtools)
library(httr2)

# ---- Load internal sysdata.rda file with URLs ----
load_all(".")

# ---- Download data ----
query_url <-
query_urls |>
filter(id == "religion") |>
pull(query)

download <- tempfile(fileext = ".zip")

request(query_url) |>
req_perform(download)

unzip(download, exdir = tempdir())

list.files(tempdir())

raw_lsoa21 <- read_csv(file.path(tempdir(), "census2021-ts030-lsoa.csv"))

names(raw_lsoa21) <- str_remove(names(raw_lsoa21), "Religion: ")

# ---- Detailed ethnic categories ----
religion21_lsoa21 <-
raw_lsoa21 |>
select(lsoa21_code = `geography code`, total_residents = `Total: All usual residents`, !contains(":"), -date, -geography) |>
pivot_longer(cols = -c(lsoa21_code, total_residents), names_to = "religion", values_to = "n") |>
mutate(prop = n / total_residents)

# ---- Save output to data/ folder ----
usethis::use_data(religion21_lsoa21, overwrite = TRUE)
Binary file added data/religion21_lsoa21.rda
Binary file not shown.
28 changes: 28 additions & 0 deletions man/religion21_lsoa21.Rd

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

0 comments on commit 393709c

Please sign in to comment.