Public
Edited
Nov 18, 2022
Insert cell
Insert cell
viewof selectedState = Inputs.select([null].concat(stateList), {label: "State"})
Insert cell
stateList = _.uniqBy(voters_ge15CSV, d => d.state)
.map(d => d.state)
.sort()
Insert cell
filteredState = voters_ge15CSV.filter(d => d.state == selectedState )
Insert cell
function newVoters(a, b) {
return a - b
}
Insert cell
function newVotersPct(a, b) {
return (a - b) / b;
}
Insert cell
ageGroup = filteredState.map((d) => ({
state: d.state,
parlimen: d.parlimen,
dun: d.dun,
total: d.total,
total_ge14: d.total_ge14,
new_voters: newVoters(d.total, d.total_ge14),
pct_new_voters: newVotersPct(d.total, d.total_ge14),
age_18_20: d.male_18_20 + d.female_18_20,
age_21_29: d.male_21_29 + d.female_21_29,
age_30_39: d.male_30_39 + d.female_30_39,
age_40_49: d.male_40_49 + d.female_40_49,
age_50_59: d.male_50_59 + d.female_50_59,
age_above60:
d.male_60_69 +
d.female_60_69 +
d.male_70_79 +
d.female_70_79 +
d.male_80_89 +
d.female_80_89 +
d["male_90+"] +
d["female_90+"]
}))
Insert cell
viewof bins = Inputs.range([5,100], {default:40, step: 10, label: "Bins"})
Insert cell
Plot.plot({
marks: [
Plot.rectY(ageGroup, Plot.binX({ y: "sum" }, { x: "total" })),
Plot.ruleY([0])
]
})
Insert cell
colorRange = ["#a6cee3","#1f78b4","#2bdf8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f","#ff7f00","#cab2d6","#ffbfff","#0000ff","#6a3d9a","#3388ff","#f933ff"]
Insert cell
voters_ge15.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

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

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

Insert cell
voters_ge15CSV= FileAttachment("voters_ge15.csv").csv({typed: true})
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