-
Notifications
You must be signed in to change notification settings - Fork 2
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 #13 from humaniverse/protected-char
Added datasets on disability, sexual orientation, age and gender and…
- Loading branch information
Showing
21 changed files
with
526 additions
and
1 deletion.
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,74 @@ | ||
# ---- 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 == "age_gender_ltla21_ew") |> | ||
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-ts009-ltla.csv")) # No data available at LSOA level | ||
|
||
# ---- Clean data ---- | ||
age_gender21_ltla21_ew <- | ||
raw |> | ||
mutate( | ||
younger_females = | ||
`Sex: Female; Age: Aged under 1 year; measures: Value` + | ||
`Sex: Female; Age: Aged 4 years and under; measures: Value` + | ||
`Sex: Female; Age: Aged 5 to 9 years; measures: Value` + | ||
`Sex: Female; Age: Aged 10 to 15 years; measures: Value`, | ||
working_age_females = | ||
`Sex: Female; Age: Aged 16 to 19 years; measures: Value` + | ||
`Sex: Female; Age: Aged 20 to 24 years; measures: Value` + | ||
`Sex: Female; Age: Aged 25 to 34 years; measures: Value` + | ||
`Sex: Female; Age: Aged 35 to 49 years; measures: Value` + | ||
`Sex: Female; Age: Aged 50 to 64 years; measures: Value`, | ||
older_females = | ||
`Sex: Female; Age: Aged 65 to 74 years; measures: Value`, + | ||
`Sex: Female; Age: Aged 75 to 84 years; measures: Value` + | ||
`Sex: Female; Age: Aged 85 years and over; measures: Value` + | ||
`Sex: Female; Age: Aged 90 years and over; measures: Value`, | ||
younger_males = | ||
`Sex: Male; Age: Aged under 1 year; measures: Value` + | ||
`Sex: Male; Age: Aged 4 years and under; measures: Value` + | ||
`Sex: Male; Age: Aged 5 to 9 years; measures: Value` + | ||
`Sex: Male; Age: Aged 10 to 15 years; measures: Value`, | ||
working_age_males = | ||
`Sex: Male; Age: Aged 16 to 19 years; measures: Value` + | ||
`Sex: Male; Age: Aged 20 to 24 years; measures: Value` + | ||
`Sex: Male; Age: Aged 25 to 34 years; measures: Value` + | ||
`Sex: Male; Age: Aged 35 to 49 years; measures: Value` + | ||
`Sex: Male; Age: Aged 50 to 64 years; measures: Value`, | ||
older_males = | ||
`Sex: Male; Age: Aged 65 to 74 years; measures: Value`, + | ||
`Sex: Male; Age: Aged 75 to 84 years; measures: Value` + | ||
`Sex: Male; Age: Aged 85 years and over; measures: Value` + | ||
`Sex: Male; Age: Aged 90 years and over; measures: Value`, | ||
) |> | ||
select( | ||
ltla21_code = `geography code`, | ||
total_population = `Sex: All persons; Age: Total; measures: Value`, | ||
total_females = `Sex: Female; Age: Total; measures: Value`, | ||
total_males = `Sex: Male; Age: Total; measures: Value`, | ||
younger_females, working_age_females, older_females, younger_males, working_age_males, older_males | ||
) | ||
|
||
|
||
# ---- Save output to data/ folder ---- | ||
usethis::use_data(age_gender21_ltla21_ew, 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,30 @@ | ||
# ---- Load libs ---- | ||
library(tidyverse) | ||
library(geographr) | ||
library(devtools) | ||
library(rio) | ||
|
||
# ---- Load internal sysdata.rda file with URLs ---- | ||
load_all(".") | ||
|
||
# ---- Download data ---- | ||
query_url <- | ||
query_urls |> | ||
filter(id == "disability21_lgd21_ni") |> | ||
pull(query) | ||
|
||
raw <- import(query_url, which = "LGD") | ||
colnames(raw) <- raw[8,] | ||
|
||
# ---- Clean data ---- | ||
disability21_lgd21_ni <- raw |> | ||
slice(9:19) |> | ||
pivot_longer(cols = (4:6), names_to = "disability", values_to = "count") |> | ||
mutate(prop = as.integer(count)/as.integer(`All households`)) |> | ||
select(lgd21_code = `Geography code`, | ||
disability, | ||
count, | ||
prop) | ||
|
||
# ---- Save output to data/ folder ---- | ||
usethis::use_data(disability21_lgd21_ni, 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,41 @@ | ||
# ---- 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 == "disability21_lsoa21_ew") |> | ||
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-lsoa.csv")) | ||
|
||
names(raw) <- str_remove(names(raw), "Disability: ") | ||
|
||
# ---- Detailed ethnic categories ---- | ||
disability21_lsoa21_ew <- | ||
raw |> | ||
select( | ||
lsoa21_code = `geography code`, | ||
total_residents = `Total: All usual residents`, !contains(":"), -date, -geography | ||
) |> | ||
pivot_longer(cols = -c(lsoa21_code, total_residents), names_to = "disability", values_to = "n") |> | ||
mutate(prop = n / total_residents) |> | ||
relocate(total_residents, .before = prop) | ||
|
||
# ---- Save output to data/ folder ---- | ||
usethis::use_data(disability21_lsoa21_ew, 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
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,31 @@ | ||
# ---- Load libs ---- | ||
library(tidyverse) | ||
library(geographr) | ||
library(devtools) | ||
library(rio) | ||
|
||
# ---- Load internal sysdata.rda file with URLs ---- | ||
load_all(".") | ||
|
||
# ---- Download data ---- | ||
query_url <- | ||
query_urls |> | ||
filter(id == "religion21_lgd21_ni") |> | ||
pull(query) | ||
|
||
raw <- import(query_url, which = "LGD") | ||
colnames(raw) <- raw[8,] | ||
|
||
# ---- Clean data ---- | ||
religion21_lgd21_ni <- raw |> | ||
slice(9:19) |> | ||
pivot_longer(cols = (4:11), names_to = "religion", values_to = "count") |> | ||
mutate(prop = as.integer(count)/as.integer(`All usual residents`)) |> | ||
select(lgd21_code = `Geography code`, | ||
religion, | ||
count, | ||
prop) |> | ||
mutate(religion = str_replace(religion, "Catholic \\r\\n\\[note 2\\]", "Catholic")) | ||
|
||
# ---- Save output to data/ folder ---- | ||
usethis::use_data(religion21_lgd21_ni, 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,30 @@ | ||
# ---- Load libs ---- | ||
library(tidyverse) | ||
library(geographr) | ||
library(devtools) | ||
library(rio) | ||
|
||
# ---- Load internal sysdata.rda file with URLs ---- | ||
load_all(".") | ||
|
||
# ---- Download data ---- | ||
query_url <- | ||
query_urls |> | ||
filter(id == "sexualorientation21_lgd21_ni") |> | ||
pull(query) | ||
|
||
raw <- import(query_url, which = "MS-C01") | ||
colnames(raw) <- raw[7,] | ||
|
||
# ---- Clean data ---- | ||
sexualorientation21_lgd21_ni <- raw |> | ||
slice(9:19) |> | ||
pivot_longer(cols = (4:9), names_to = "sexual_orientation", values_to = "count") |> | ||
mutate(prop = as.integer(count)/as.integer(`All usual residents aged 16 and over`)) |> | ||
select(lgd21_code = `Geography code`, | ||
sexual_orientation, | ||
count, | ||
prop) | ||
|
||
# ---- Save output to data/ folder ---- | ||
usethis::use_data(sexualorientation21_lgd21_ni, overwrite = TRUE) |
Oops, something went wrong.