Public
Edited
Apr 16, 2023
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
import { require } from "@observablehq/stdlib";
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
filtered_results = dataset.filter(d => d.year >= 2015 && d.year <= 2019)
Insert cell
DOM.download(serialize(filtered_results), null, "Download JSON")
Insert cell
filteredResults3= dataset.filter(d => d.year >= 2011 && d.year <= 2019)
Insert cell
filtered5years= dataset.filter(d => d.year >= 2003 && d.year <= 2019)
Insert cell
filtered5years
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
DOM.download(serialize(filtered5years), null, "Download JSON")
Insert cell
Insert cell
//list of parties in all the municipalities

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
Insert cell
Insert cell
resultCouncilorsDifferenceMainParties = Object.values(groupedCouncilorsMainParty);
Insert cell
//to calculate the councilors difference by region per year (main parties)
groupedCouncilorsMainPartyRegion = filtered_results.reduce((acc, curr) => {
const key = curr.region + curr.main_party;
const yearDiff = curr.year - (acc[key]?.year || 0);
acc[key] = {
region: curr.region,
main_party: curr.main_party,
year: curr.year,
councilor_diff: yearDiff === 4 ? curr.councilors - acc[key].councilors : null,
councilors: curr.councilors,
};
return acc;
}, {});
Insert cell
Plot.plot({
marks: [
Plot.barY(resultCouncilorsDifferenceMainParties, {x: "main_party", y: "councilor_diff", sort: {x: "y", reverse: true}}),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
Insert cell
resultCouncilorsDifferenceMainParties3 = Object.values(groupedCouncilorsMainParty3);
Insert cell
Plot.plot({
//grid: true,
//inset: 10,
width: 1624,
height: 540,
color: {
type: "ordinal",
scheme: "category10",
legend: true
},
facet: {
data: filteredResults3,
x: "region",
},
marks: [
Plot.frame(),
Plot.dot(filteredResults3, {x: "main_party", y: "councilors", fill: "year"})
]
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import {GroupedBarChart} from "@d3/grouped-bar-chart"
Insert cell
Insert cell
function serialize (data) {
let s = JSON.stringify(data);
return new Blob([s], {type: "application/json"})
}
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