Skip to content

Commit 6d7ff0e

Browse files
committed
Adding population estimates mid-2023 LA level
1 parent 055bbb5 commit 6d7ff0e

4 files changed

Lines changed: 3587 additions & 0 deletions

File tree

population/mid_year_2023/index.Rmd

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
pagetitle: "Mid-2023 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_2023_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-2023 population estimates</h1>
24+
*Estimates of the usual resident population in Trafford during mid-2023.*
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="2023-06-30">2023-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="2024-09-13">2024-09-13</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+
<div id = "renderDT">
58+
59+
```{r preview}
60+
datatable(df,
61+
class = 'cell-border stripe',
62+
rownames = FALSE,
63+
extensions = c('Scroller', 'Buttons', 'KeyTable'),
64+
options = list(
65+
keys = TRUE,
66+
search = list(regex = TRUE),
67+
searchHighlight = TRUE,
68+
dom = 'ftB',
69+
buttons = list(
70+
list(extend = "csv",
71+
text = "Download selection")),
72+
deferRender = TRUE,
73+
scrollX = TRUE,
74+
scrollY = 120,
75+
scroller = TRUE,
76+
columnDefs = list(
77+
list(className = 'dt-left', targets = "_all")
78+
)))
79+
```
80+
</div>
81+
<div id="tableFooterTitle">Mid-2023 population estimates for Trafford</div>
82+
83+
<h2>Data</h2>
84+
<span id ="downloads">Download the complete dataset using the following links:</span>
85+
86+
|File name |Format |
87+
|---|---|
88+
|[mid-year_2023_population_estimates_local_authority.csv](mid-year_2023_population_estimates_local_authority.csv) |CSV |
89+
90+
<h2>Pre-processing</h2>
91+
[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>.
92+
93+
</main>
94+
95+
<script>
96+
// Fixes to dynamic elements created by DataTables to improve accessibility
97+
var removeElFn = setInterval(removeElement, 1000);
98+
99+
function removeElement() {
100+
try {
101+
var el = document.getElementsByClassName("dataTables_scrollBody")[0].childNodes[0];
102+
el.removeChild(el.childNodes[0]); // Remove unwanted hidden text element from table - causing accessibility alert as it has no label
103+
104+
el.parentNode.setAttribute('tabindex', '0'); // add attribute allowing keyboard users to access scrollable area
105+
106+
clearInterval(removeElFn); // cancel any further calls to this function as we have completed all actions
107+
}
108+
catch(e) {
109+
// form element 'el' doesn't exist yet so setInterval will call the function again until it does
110+
}
111+
}
112+
</script>

population/mid_year_2023/index.html

Lines changed: 3440 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+
2023-06-30,E08000009,Trafford,Local authority,Persons,237480,49827,145580,42073,2188,2339,2526,2655,3041,3002,3180,3343,3273,3452,3439,3628,3715,3348,3382,3316,3148,3040,2735,1970,1613,1912,1977,2456,2575,2538,2580,2514,2473,2529,2642,2810,2913,2945,3148,3165,3190,3516,3584,3600,3546,3566,3824,3669,3595,3375,3198,3142,3249,3121,3184,3377,3364,3326,3142,3162,3104,3122,3158,3116,3000,2801,2710,2636,2520,2431,2312,2212,2132,2042,1958,1976,1997,1994,1964,2105,2128,1580,1597,1599,1454,1170,1104,1109,1138,1003,879,789,674,575,2151
3+
2023-06-30,E08000009,Trafford,Local authority,Females,121563,24246,74192,23125,1030,1117,1192,1287,1524,1454,1598,1654,1582,1671,1677,1748,1816,1620,1639,1637,1529,1491,1342,954,680,917,991,1247,1267,1242,1215,1340,1181,1249,1326,1432,1560,1592,1722,1639,1745,1826,1893,1918,1856,1879,1991,1888,1898,1750,1636,1646,1602,1575,1612,1722,1697,1688,1546,1576,1602,1610,1572,1598,1510,1423,1421,1325,1271,1237,1167,1100,1111,1041,1040,1031,1053,1085,1029,1101,1156,894,906,916,831,669,642,680,648,574,521,466,403,358,1466
4+
2023-06-30,E08000009,Trafford,Local authority,Males,115917,25581,71388,18948,1158,1222,1334,1368,1517,1548,1582,1689,1691,1781,1762,1880,1899,1728,1743,1679,1619,1549,1393,1016,933,995,986,1209,1308,1296,1365,1174,1292,1280,1316,1378,1353,1353,1426,1526,1445,1690,1691,1682,1690,1687,1833,1781,1697,1625,1562,1496,1647,1546,1572,1655,1667,1638,1596,1586,1502,1512,1586,1518,1490,1378,1289,1311,1249,1194,1145,1112,1021,1001,918,945,944,909,935,1004,972,686,691,683,623,501,462,429,490,429,358,323,271,217,685
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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(tidyverse)
8+
9+
#Local authority
10+
11+
# Local authority
12+
la <- read_csv("https://www.nomisweb.co.uk/api/v01/dataset/NM_2002_1.data.csv?geography=1778385132&date=latest&gender=0...2&c_age=101...191&measures=20100") %>%
13+
mutate(geography = "Local authority") %>%
14+
select(period = DATE_NAME,
15+
area_code = GEOGRAPHY_CODE,
16+
area_name = GEOGRAPHY_NAME,
17+
sex = GENDER_NAME,
18+
age = C_AGE_NAME,
19+
count = OBS_VALUE,
20+
geography) %>%
21+
mutate(period = ymd(str_c(period, "06-30", sep = "-")),
22+
sex = factor(fct_recode(sex, "Females" = "Female" , "Males" = "Male", "Persons" = "Total"), levels = c("Persons", "Females", "Males")),
23+
age = as.integer(str_trim(str_replace_all(age, "Age.|\\+", "")))) %>%
24+
spread(age, count) %>%
25+
mutate(all_ages = rowSums(select(., `0`:`90`)),
26+
aged_0_to_15 = rowSums(select(., `0`:`15`)),
27+
aged_16_to_64 = rowSums(select(., `16`:`64`)),
28+
aged_65_and_over = rowSums(select(., `65`:`90`))) %>%
29+
select(period, area_code, area_name, geography, sex, all_ages, aged_0_to_15, aged_16_to_64, aged_65_and_over, everything(), `90+` = `90`)
30+
31+
write_csv(la, "mid-year_2023_population_estimates_local_authority.csv")

0 commit comments

Comments
 (0)