Public
Edited
Jun 26, 2024
Insert cell
Insert cell
data = FileAttachment("milbudget - data-3.tsv").tsv()
Insert cell
long = data
.flatMap(
(
c // flatMap maps each value to an array and then flattens it to single array
) =>
Object.keys(c)
.slice(2, data.length + 1)
.map((d) => ({
// map each year to separate object
country: c.country,
reg: c.dem,
year: d,
value: +c[d]
}))
)
.filter((d) => d.year == "y23")
Insert cell
data2 = (await FileAttachment("rating.csv").csv()).map((d) => {
return { ...d, y23: +d.y23, Overall_score: +d.Overall_score };
})
Insert cell
Plot.plot({
width: 950,
x: { type: "linear" },
// fx: {
// domain: [
// "Authoritarian regime",
// "Hybrid regime",
// "Flawed democracy",
// "Full democracy"
// ]
// },
marks: [
Plot.frame(),
Plot.dot(data2, {
x: "Overall_score",
y: "y23",
fill: "Regime_type",
tip: true,
title: (d) => `${d.Country}`
// fx: "Regime_type"
// sort: { fx: "-x" }
}),
Plot.ruleY(
data2,
Plot.groupX({ y: "mean" }, { x: "Regime_type", y: "y23", stroke: "red" })
)
]
})
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