Public
Edited
Nov 30, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
profileDoc = (Array.from(new Set(PQsFilteredByConstituency1.map(d => d.constProfile)))[0])
Insert cell
Insert cell
questionsChart = Plot.plot({
width: 800,
marginTop: -10,
marginLeft: 230,
marginRight: 40,
subtitle: htl.html`<h2>Popular parliamentary question topics in ${thisYear} | <strong>${constituencyPicker}</strong></h2>`,
x: {label: "Number of questions"},
y: {label: "Question topic"},
marks: [
Plot.barX(topQuestions, {x: "1", y: "0", fill: "#1f77b4", tip: true, sort: {y: "x", reverse: true}}),
Plot.ruleX([0]),
Plot.axisX({fontSize:12}),
Plot.axisY({fontSize:12})
]
})
Insert cell
Insert cell
working_population.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
experiment = Array.from(d3.flatRollup(oneConstituency, v => d3.sum(v, d => d.total), d => d.group, d => d.sex), ([group, Gender, total]) => ({group, Gender, total}))
Insert cell
oneConstituency = tidyData.filter(d => d.constituency === `${constituencyPicker}`)
Insert cell
tidyData = refinedData.map(d => ({constituency: d.constituency, district: d.district, sex: (d.ageGroup.slice(0,1)), group: d.ageGroup.slice(2), total: d.total}))
Insert cell
refinedData = (Object.getOwnPropertyNames(population[0]).slice(2)).flatMap((ageGroup) => population.map(d => ({constituency: d.constituency, district: d.district, ageGroup, total: d[ageGroup]})))
Insert cell
Insert cell
Insert cell
Insert cell
employmentChart = Plot.plot({
style: {fontSize: 12, fontFamily: "IBM Plex Sans"},
marginTop: 50,
color: {scheme: "Category10"},
marginLeft: 150,
marginBottom: 95,
subtitle: htl.html`<h3>Employment types in ${constituencyPicker}</h3>`,
width: 800,
x: {
label: "Employment sector", tickRotate: 15,
},
y: {grid: true, label: "Number of workers", nice: true},
marks: [
Plot.barY(workingTotals, {x: "sector", y: "total", fill: "#1f77b4", tip: true,
}),
Plot.ruleY([0])
]
})
Insert cell
HousingChart = Plot.plot({
style: {fontSize: 12, fontFamily: "IBM Plex Sans"},
marginTop: 50,
marginLeft: 150,
marginBottom: 90,
subtitle: htl.html`<h3>Housing in ${constituencyPicker}</h3>`,
width: 800,
x: {
label: "Housing type", tickRotate: -10,
},
y: {grid: true, label: "Number of properties", nice: true},
color: {scheme: "Tableau10", legend: false},
marks: [
Plot.barY(housingTotals, {x: "housing", y: "total", fill: "#ff7f0e", tip: true, sort:{x: "y", reverse: true}
}),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
Insert cell
Insert cell
newconstituencies = FileAttachment("constituenciesFromAPI-3.json").json()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
constituencyTDs = Array.from(
//Construct an array of Deputy info containing Deputy name, party and constituency
d3.flatGroup(
members.results.filter(
(d) => d.member.memberships[0].membership.dateRange.end === null
),
(d) => d.member.memberships[0].membership.house.showAs,
(d) => d.member.fullName,
(d) =>
d.member.memberships[0].membership.parties[
d.member.memberships[0].membership.parties.length - 1
].party.showAs,
(d) =>
d.member.memberships[d.member.memberships.length - 1].membership
.represents[0].represent.representCode,
(d) =>
d.member.memberships[d.member.memberships.length - 1].membership
.represents[0].represent.showAs,
(d) => d.member.memberCode
),
([House, name, Party, representCode, constituency, uri]) => ({
House,
name,
Party,
representCode,
constituency,
uri
})
).sort((a, b) => d3.ascending(a, b))
Insert cell
Insert cell
Insert cell
Insert cell
list3 = TDs.slice(-1).map(d => d.name+".")
Insert cell
membersWithProfile = Array.from(d3.flatGroup(TDsTest, d => d.name, d => d.memberProfile),
([name, profile]) => ({name, profile}))
Insert cell
membersWithProfile.slice(0,-1)
Insert cell
testList3 = TDsTest.slice(-1).map(d => d.name+".")
Insert cell
Insert cell
listDeputy2 = TDs.slice(1,2).map(d => d.name+", ")
Insert cell
listDeputy3 = TDs.slice(2,3).map(d => d.name+", ")
Insert cell
listDeputy1 = TDs.slice(0,1).map(d => d.name+" ")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import {rolledWithConstituencyMemberCode} from "4a09f5dffdde7d16"
Insert cell
rolledWithConstituencyMemberCode
Insert cell
thisYear = new Date(filteredPQs[0].date).toLocaleString(undefined, {
"year": "numeric",
})
Insert cell
filteredPQs = rolledWithConstituencyMemberCode.filter(d => d.name != null)
Insert cell
topQuestions = Array.from(d3.rollup(filteredPQs.filter(d => d.constituency == `${constituencyPicker}`), v => v.length, d => d.heading)).slice().sort((a, b) => d3.descending(a[1], b[1])).slice(0,20)
Insert cell
constituenciesWithProfiles - constituencyTDs@1.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Array.from(new Set(constituencieswithprofilesConstituencytds.map(d => d.constituency)))
Insert cell
format = d3.format(",d")
Insert cell
population = constituency_population_age2.flatMap(d => ({constituency: d["NEW CONSTITUENCY"], district: d["GEOGDESC"], "M 0 to 9": d["Age 0 - Males"]+d["Age 1 - Males"]+d["Age 2 - Males"]+d["Age 3 - Males"]+d["Age 4 - Males"]+d["Age 5 - Males"]+d["Age 6 - Males"]+d["Age 7 - Males"]+d["Age 8 - Males"]+d["Age 9 - Males"], "M 10 to 19": d["Age 10 - Males"]+d["Age 11 - Males"]+d["Age 12 - Males"]+d["Age 13 - Males"]+d["Age 14 - Males"]+d["Age 15 - Males"]+d["Age 16 - Males"]+d["Age 17 - Males"]+d["Age 18 - Males"]+d["Age 19 - Males"], "M 20 to 29": d["Age 20 - 24 - Males"]+d["Age 25 - 29 - Males"], "M 30 to 39": d["Age 30 - 34 - Males"]+d["Age 35 - 39 - Males"], "M 40 to 49": d["Age 40 - 44 - Males"]+d["Age 45 - 49 - Males"], "M 50 to 59": d["Age 50 - 54 - Males"]+d["Age 55 - 59 - Males"], "M 60 to 69": d["Age 60 - 64 - Males"]+d["Age 65 - 69 - Males"], "M 70 to 79": d["Age 70 - 74 - Males"]+d["Age 75 - 79 - Males"], "M 80 and over": d["Age 80 - 84 - Males"]+d["Age 85 and over - Males"], "F 0 to 9": d["Age 0 - Females"]+d["Age 1 - Females"]+d["Age 2 - Females"]+d["Age 3 - Females"]+d["Age 4 - Females"]+d["Age 5 - Females"]+d["Age 6 - Females"]+d["Age 7 - Females"]+d["Age 8 - Females"]+d["Age 9 - Females"], "F 10 to 19": d["Age 10 - Females"]+d["Age 11 - Females"]+d["Age 12 - Females"]+d["Age 13 - Females"]+d["Age 14 - Females"]+d["Age 15 - Females"]+d["Age 16 - Females"]+d["Age 17 - Females"]+d["Age 18 - Females"]+d["Age 19 - Females"], "F 20 to 29": d["Age 20 - 24 - Females"]+d["Age 25 - 29 - Females"], "F 30 to 39": d["Age 30 - 34 - Females"]+d["Age 35 - 39 - Males"], "F 40 to 49": d["Age 40 - 44 - Females"]+d["Age 45 - 49 - Females"], "F 50 to 59": d["Age 50 - 54 - Females"]+d["Age 55 - 59 - Females"], "F 60 to 69": d["Age 60 - 64 - Females"]+d["Age 65 - 69 - Females"], "F 70 to 79": d["Age 70 - 74 - Females"]+d["Age 75 - 79 - Females"], "F 80 and over": d["Age 80 - 84 - Females"]+d["Age 85 and over - Females"]}))
Insert cell
household_type.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
constituency_population_age-2.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
householdTypeData = FileAttachment("household_type.csv").csv({typed: true})
Insert cell
households = householdTypeData.flatMap(d => ({constituency: d["NEW CONSTITUENCY"], district: d["GEOGDESC"], "Owned with mortgage or loan": d["Owned with mortgage or loan (No. of households)"], "Owned outright": d["Owned outright (No. of households)"], "Rented from private landlord": d["Rented from private landlord (No. of households) "], "Rented from local authority": d["Rented from Local Authority (No. of households)"], "Rented from voluntary or cooperative housing body": d["Rented from voluntary/co-operative housing body (No. of households)"], "Occupied free of rent": d["Occupied free of rent (No. of households)"], "Not stated": d["Not stated (No. of households)"]}))
Insert cell
tidyDataforHouseholds = (Object.getOwnPropertyNames(households[0]).slice(2)).flatMap((housing) => households.map(d => ({constituency: d.constituency, district: d.district, housing, total: d[housing]})))

Insert cell
oneConstituencyforHouseholds = tidyDataforHouseholds.filter(d => d.constituency === `${constituencyPicker}`)
Insert cell
housingTotals = Array.from(d3.flatRollup(oneConstituencyforHouseholds, v => d3.sum(v, d => d.total), d => d.housing), ([housing, total]) => ({housing, total}))
Insert cell
workingData = FileAttachment("working_population.csv").csv({typed: true})
Insert cell
workingPopulation = workingData.flatMap(d => ({constituency: d["NEW CONSTITUENCY"], district: d["GEOGDESC"], "Employers and managers": d["Employers and managers (No. of persons)"], "Higher professionals": d["Higher professional (No. of persons)"], "Lower professionals": d["Lower professional (No. of persons)"], "Non-manual": d["Non-manual (No. of persons)"], "Manual skilled": d["Manual skilled (No. of persons)"], "Semi-skilled": d["Semi-skilled (No. of persons)"], "Unskilled": d["Unskilled (No. of persons)"], "Own account workers": d["Own account workers (No. of persons)"], "Farmers": d["Farmers (No. of persons)"], "Agricultural workers": d["Agricultural workers (No. of persons)"], "All others gainfully occupied and unknown": d["All others gainfully occupied and unknown (No. of persons)"] }))
Insert cell
tidyWorkingData = (Object.getOwnPropertyNames(workingPopulation[0]).slice(2)).flatMap((sector) => workingPopulation.map(d => ({constituency: d.constituency, district: d.district, sector, total: d[sector]})))
Insert cell
oneConstituencyforWork = tidyWorkingData.filter(d => d.constituency === `${constituencyPicker}`)
Insert cell
workingTotals = Array.from(d3.flatRollup(oneConstituencyforWork, v => d3.sum(v, d => d.total), d => d.sector), ([sector, total]) => ({sector, total}))
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more