Skip to content

Commit e0dbdcb

Browse files
committed
Mid Year 2022 for Trafford local authority level
1 parent 171117f commit e0dbdcb

4 files changed

Lines changed: 3523 additions & 0 deletions

File tree

population/mid_year_2022/index.Rmd

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
pagetitle: "Mid-2022 population estimates"
3+
lang: "en-GB"
4+
output:
5+
html_document:
6+
css: ../../guidance/template/styles.css
7+
self_contained: TRUE
8+
---
9+
10+
```{r setup, include=FALSE}
11+
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
12+
library(tidyverse) ; library(htmltools) ; library(DT)
13+
14+
df <- read_csv("mid-year_2022_population_estimates_local_authority.csv") %>%
15+
rename_all(. %>% str_to_title() %>% str_replace_all("_", " ")) %>%
16+
mutate(`Area name` = factor(`Area name`)) %>%
17+
rename_all(. %>% str_to_title())
18+
```
19+
<header>
20+
<span id="a11yNav"><a href="#downloads" class="themeBlockDark">Skip to downloads</a></span>
21+
<a href="https://www.trafforddatalab.io/data.html"><img src="https://www.trafforddatalab.io/assets/logo/trafforddatalab_logo.svg" alt="Trafford Data Lab" aria-label="Return to Trafford Data Lab data page" width="100" class="traffordDataLabLogo"/></a>
22+
23+
<h1>Mid-2022 population estimates</h1>
24+
*Estimates of the usual resident population in Trafford during mid-2022.*
25+
26+
</header>
27+
28+
<main>
29+
<h2>Metadata</h2>
30+
31+
<table id="metadata" class="table table-condensed">
32+
<thead>
33+
<tr class="header">
34+
<th>Source</th>
35+
<th>Publisher</th>
36+
<th>Time period</th>
37+
<th>Geography</th>
38+
<th>Licence</th>
39+
<th>Attribution</th>
40+
<th>Last updated</th>
41+
</tr>
42+
</thead>
43+
<tr>
44+
<td>Office for National Statistics</td>
45+
<td><a href="https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/estimatesofthepopulationforenglandandwales" target="_blank">Office for National Statistics</a></td>
46+
<td><time datetime="2022-06-30">2022-06-30</time></td>
47+
<td>Local authority</td>
48+
<td><a href="http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/" target="_blank">OGL v3.0</a></td>
49+
<td>Contains public sector information licensed under the Open Government Licence v3.0</td>
50+
<td><time datetime="2023-11-24">2023-11-24</time></td>
51+
</tr>
52+
</table>
53+
54+
<h2>Preview</h2>
55+
Sort, filter and export a selection of the data using the table.
56+
57+
```{r preview}
58+
datatable(df,
59+
class = 'cell-border stripe',
60+
rownames = FALSE,
61+
extensions = c('Scroller', 'Buttons', 'KeyTable'),
62+
options = list(
63+
keys = TRUE,
64+
search = list(regex = TRUE),
65+
searchHighlight = TRUE,
66+
dom = 'ftB',
67+
buttons = list(
68+
list(extend = "csv",
69+
text = "Download selection")),
70+
deferRender = TRUE,
71+
width = NULL,
72+
scrollX = TRUE,
73+
scrollY = 120,
74+
scroller = TRUE,
75+
columnDefs = list(
76+
list(className = 'dt-left', targets = "_all"),
77+
list(visible = TRUE, targets = "_all")
78+
)))
79+
```
80+
<div id="tableFooterTitle">Mid-2022 population estimates for Trafford's wards</div>
81+
82+
<h2>Data</h2>
83+
<span id ="downloads">Download the complete dataset using the following links:</span>
84+
85+
|File name |Format |
86+
|---|---|
87+
|[mid-year_2022_population_estimates_local_authority.csv](mid-year_population_estimates_local_authority.csv) |CSV |
88+
89+
<h2>Pre-processing</h2>
90+
[The R script used to process the data](pre-processing.R) can be adapted to other areas. For information about R visit the <a href="https://cran.r-project.org" target="_blank">CRAN website</a>.
91+
92+
</main>
93+
94+
<script>
95+
// Fixes to dynamic elements created by DataTables to improve accessibility
96+
var removeElFn = setInterval(removeElement, 1000);
97+
98+
function removeElement() {
99+
try {
100+
var el = document.getElementsByClassName("dataTables_scrollBody")[0].childNodes[0];
101+
el.removeChild(el.childNodes[0]); // Remove unwanted hidden text element from table - causing accessibility alert as it has no label
102+
103+
el.parentNode.setAttribute('tabindex', '0'); // add attribute allowing keyboard users to access scrollable area
104+
105+
clearInterval(removeElFn); // cancel any further calls to this function as we have completed all actions
106+
}
107+
catch(e) {
108+
// form element 'el' doesn't exist yet so setInterval will call the function again until it does
109+
}
110+
}
111+
</script>

population/mid_year_2022/index.html

Lines changed: 3373 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
period,area_code,area_name,geography,sex,all_ages,aged_0_to_15,aged_16_to_64,aged_65_and_over,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90+
2+
2022-06-30,E08000009,Trafford,Local authority,Persons,236301,49323,145158,41820,2283,2426,2507,2888,2872,3049,3242,3110,3365,3282,3517,3684,3307,3343,3298,3150,3030,2981,2726,1728,1804,1713,2192,2486,2443,2547,2375,2431,2451,2563,2753,2849,2884,3087,3086,3163,3439,3509,3564,3497,3526,3801,3632,3598,3377,3195,3176,3276,3156,3211,3442,3401,3372,3225,3211,3183,3205,3210,3212,3075,2879,2764,2671,2581,2478,2355,2261,2187,2102,2009,1998,2030,2050,2018,2166,2192,1631,1667,1663,1538,1240,1169,1183,1225,1079,989,902,757,660,615,2134
3+
2022-06-30,E08000009,Trafford,Local authority,Females,121052,24013,74021,23018,1115,1146,1197,1446,1394,1533,1605,1509,1627,1572,1684,1806,1597,1618,1629,1535,1488,1453,1325,779,864,838,1114,1231,1200,1225,1268,1186,1191,1267,1374,1529,1533,1663,1622,1720,1783,1840,1891,1821,1878,1987,1878,1889,1751,1635,1660,1617,1600,1626,1759,1725,1728,1599,1612,1627,1649,1599,1649,1565,1449,1448,1339,1298,1249,1184,1108,1138,1067,1065,1041,1066,1115,1049,1129,1183,907,944,944,875,699,674,715,696,616,586,536,445,399,373,1464
4+
2022-06-30,E08000009,Trafford,Local authority,Males,115249,25310,71137,18802,1168,1280,1310,1442,1478,1516,1637,1601,1738,1710,1833,1878,1710,1725,1669,1615,1542,1528,1401,949,940,875,1078,1255,1243,1322,1107,1245,1260,1296,1379,1320,1351,1424,1464,1443,1656,1669,1673,1676,1648,1814,1754,1709,1626,1560,1516,1659,1556,1585,1683,1676,1644,1626,1599,1556,1556,1611,1563,1510,1430,1316,1332,1283,1229,1171,1153,1049,1035,944,957,964,935,969,1037,1009,724,723,719,663,541,495,468,529,463,403,366,312,261,242,670
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#Mid-year estimates at Local authority level
2+
3+
# Source: ONS
4+
# URL: https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/estimatesofthepopulationforenglandandwales
5+
# Licence: Open Government Licence 3.0
6+
7+
library(httr) ; library(readxl) ; library(tidyverse)
8+
9+
tmp <- tempfile(fileext = ".xlsx")
10+
11+
12+
GET(url = "https://www.ons.gov.uk/file?uri=/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/estimatesofthepopulationforenglandandwales/mid20222023localauthorityboundaires/mye22tablesew2023geogs.xlsx",
13+
write_disk(tmp))
14+
15+
mid2022P <- read_xlsx(tmp, sheet = 7, skip = 7) %>%
16+
filter(Code %in% c("E08000009")) %>%
17+
mutate(sex = "Persons")
18+
19+
mid2022F <- read_xlsx(tmp, sheet = 8, skip = 7) %>%
20+
filter(Code %in% c("E08000009")) %>%
21+
mutate(sex = "Females")
22+
23+
mid2022M <- read_xlsx(tmp, sheet = 9, skip = 7) %>%
24+
filter(Code %in% c("E08000009")) %>%
25+
mutate(sex = "Males")
26+
27+
df <- bind_rows(mid2022P, mid2022F, mid2022M) %>%
28+
mutate(geography = "Local authority",
29+
period = "2022-06-30") %>%
30+
mutate(aged_0_to_15 = rowSums(select(., `0`:`15`)),
31+
aged_16_to_64 = rowSums(select(., `16`:`64`)),
32+
aged_65_and_over = rowSums(select(., `65`:`90+`))) %>%
33+
select(period, area_code = Code, area_name = Name, geography, sex, all_ages = `All ages`, aged_0_to_15, aged_16_to_64, aged_65_and_over, everything(), -Geography)
34+
35+
write_csv(df, "mid-year_2022_population_estimates_local_authority.csv")

0 commit comments

Comments
 (0)