Public
Edited
Mar 21, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
plot = Plot.plot({
width,
height: 500,
marginLeft: 100,
marginRight: 50,
x: { domain: [0, 1], grid: true, ticks: 10, tickFormat: "%" },
marks: [
Plot.barX(filteredCountries, {
x: (d) => 1 - (1 - scenario) * d.percent,
y: "countryName",
stroke: "lightgray"
}),
Plot.barX(filteredCountries, {
x: "percent",
y: "countryName",
sort: { y: "x", reverse: true, limit: 50 },
stroke: "gray"
}),
Plot.barX(filteredCountries, {
x: (d) => d.percent * scenario,
y: "countryName",
fill: "black",
sort: { y: "x", reverse: true, limit: 50 }
}),
// Plot.text(filteredCountries, {
// text: (d) => d3.format("0.2%")(d.percent * scenario),
// // x: "percent",
// x: (d) => d.percent * scenario,
// y: "countryName",
// dx: 20
// }),
Plot.text(filteredCountries, {
text: (d) => pformat(1 - (1 - scenario) * d.percent),
// x: "percent",
x: (d) => 1 - (1 - scenario) * d.percent,
y: "countryName",
dx: 25
}),
Plot.ruleX([0])
]
})
Insert cell
plot.scale("x")
Insert cell
plot.scale("y")
Insert cell
pformat = d3.format("0.1%")
Insert cell
00_all_data_ukraine.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
filterNumber = 0.0
Insert cell
filteredCountries = data.filter((d) => d.percent > filterNumber)
Insert cell
Insert cell
function applyScenarioScalar(inputPercent) {
return inputPercent * scenario;
}
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