-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from humaniverse/census-2021
Census 2021
- Loading branch information
Showing
18 changed files
with
401 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# ---- 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 == "england_disability_2021") |> | ||
pull(query) | ||
|
||
download <- tempfile(fileext = ".zip") | ||
|
||
request(query_url) |> | ||
req_perform(download) | ||
|
||
unzip(download, exdir = tempdir()) | ||
|
||
list.files(tempdir()) | ||
|
||
raw <- read_csv(file.path(tempdir(), "census2021-ts038-ltla.csv")) | ||
|
||
names(raw) <- str_remove(names(raw), "Disability: ") | ||
|
||
# ---- Detailed ethnic categories ---- | ||
disability_21 <- | ||
raw |> | ||
select( | ||
ltla21_code = `geography code`, | ||
total_residents = `Total: All usual residents`, !contains(":"), -date, -geography | ||
) |> | ||
pivot_longer(cols = -c(ltla21_code, total_residents), names_to = "disability_level", values_to = "n") |> | ||
mutate(prop = n / total_residents) | ||
|
||
england_disability_21 <- disability_21 |> | ||
filter(str_detect(ltla21_code, "^E")) | ||
|
||
wales_disability_21 <- disability_21 |> | ||
filter(str_detect(ltla21_code, "^W")) | ||
|
||
# ---- Save output to data/ folder ---- | ||
usethis::use_data(england_disability_21, overwrite = TRUE) | ||
usethis::use_data(wales_disability_21, overwrite = TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# ---- 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 == "legal_partnership_status_2021") |> | ||
pull(query) | ||
|
||
download <- tempfile(fileext = ".zip") | ||
|
||
request(query_url) |> | ||
req_perform(download) | ||
|
||
unzip(download, exdir = tempdir()) | ||
|
||
list.files(tempdir()) | ||
|
||
raw <- read_csv(file.path(tempdir(), "census2021-ts002-ltla.csv")) | ||
|
||
names(raw) <- str_remove(names(raw), "Marital and civil partnership status: ") | ||
|
||
# ---- Detailed ethnic categories ---- | ||
legal_partnership_21 <- | ||
raw |> | ||
select(-date, -geography) |> | ||
rename( | ||
ltla21_code = `geography code`, | ||
total_population = `Total; measures: Value` | ||
) |> | ||
pivot_longer(cols = -c(ltla21_code, total_population), names_to = "legal_partnership", values_to = "n") |> | ||
mutate(prop = n / total_population) |> | ||
mutate(prop = format(prop, scientific = FALSE)) | ||
|
||
england_legal_partnership_21 <- legal_partnership_21 |> | ||
filter(str_detect(ltla21_code, "^E")) | ||
|
||
wales_legal_partnership_21 <- legal_partnership_21 |> | ||
filter(str_detect(ltla21_code, "^W")) | ||
|
||
# ---- Save output to data/ folder ---- | ||
usethis::use_data(england_legal_partnership_21, overwrite = TRUE) | ||
usethis::use_data(wales_legal_partnership_21, overwrite = TRUE) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# ---- 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 == "sexual_orientation_2021") |> | ||
pull(query) | ||
|
||
download <- tempfile(fileext = ".zip") | ||
|
||
request(query_url) |> | ||
req_perform(download) | ||
|
||
unzip(download, exdir = tempdir()) | ||
|
||
list.files(tempdir()) | ||
|
||
raw <- read_csv(file.path(tempdir(), "census2021-ts077-ltla.csv")) | ||
|
||
names(raw) <- str_remove(names(raw), "Sexual orientation: ") | ||
|
||
# ---- Detailed ethnic categories ---- | ||
sexual_orientation_21 <- | ||
raw |> | ||
select(-date, -geography) |> | ||
rename( | ||
ltla21_code = `geography code`, | ||
total_residents = `Total: All usual residents aged 16 years and over` | ||
) |> | ||
pivot_longer(cols = -c(ltla21_code, total_residents), names_to = "sexual_orientation", values_to = "n") |> | ||
mutate(prop = n / total_residents) |> | ||
mutate(prop = format(prop, scientific = FALSE)) | ||
|
||
england_sexual_orientation_21 <- sexual_orientation_21 |> | ||
filter(str_detect(ltla21_code, "^E")) | ||
|
||
wales_sexual_orientation_21 <- sexual_orientation_21 |> | ||
filter(str_detect(ltla21_code, "^W")) | ||
|
||
# ---- Save output to data/ folder ---- | ||
usethis::use_data(england_sexual_orientation_21, overwrite = TRUE) | ||
usethis::use_data(wales_sexual_orientation_21, overwrite = TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.