Public
Edited
Jun 14, 2024
Importers
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
countryCartogram = Plot.plot({
color: {
legend: true
},
marks: [
Plot.cell(COUNTRY_CARTOGRAM, {
x: "x",
y: "y",
fill: "state",
tip: true,
title: "electorate"
}),
Plot.text(COUNTRY_CARTOGRAM, {
x: "x",
y: "y",
text: "abbreviation"
})
]
})
Insert cell
Insert cell
gridCartogram = Plot.plot({
width: 800,
color: {
legend: true
},
marks: [
Plot.cell(GRID_CARTOGRAM, {
x: "x",
y: "y",
fill: "state",
tip: true,
title: "electorate"
}),
Plot.text(GRID_CARTOGRAM, {
x: "x",
y: "y",
text: "abbreviation"
})
]
})
Insert cell
Insert cell
Insert cell
COUNTRY_CARTOGRAM.map((d) => d.electorate)
Insert cell
joinedData = [...divisionInformality2022].map((d) => {
const cell = COUNTRY_CARTOGRAM.find((c) => d.DivisionNm === c.electorate);
return {
...d,
...cell
};
})
Insert cell
Insert cell
cartogram = Plot.plot({
title: "Divisions by informal voting rate",
color: {
domain: [0, 15],
scheme: "viridis",
label: "Informal voting (%) →",
legend: true
},
marks: [
Plot.cell(joinedData, {
x: "x",
y: "y",
fill: "InformalPercent"
}),
Plot.text(joinedData, {
x: "x",
y: "y",
fill: "black",
text: "abbreviation",
tip: true,
title: (d) =>
`${d.DivisionNm} (${d.StateAb})\nInformal: ${(
d.InformalPercent || 0
).toFixed(1)}%\nInformal swing: ${d.InformalSwing}%`
})
]
})
Insert cell
Insert cell
Insert cell
function makeCartogram(layout) {
return Object.entries(STATES_ELECTORATES_CELLS)
.flatMap(([state, electorates]) =>
Object.entries(electorates).map(([abbreviation, [x, y]]) => ({
state,
abbreviation,
x: x + layout[state][0],
y: y + layout[state][1]
}))
)
.map((cell, i) => ({
...cell,
electorate: DIVISIONS[i]
}));
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more