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) => pformat(1 - (1 - scenario) * d.percent),
x: (d) => 1 - (1 - scenario) * d.percent,
y: "countryName",
dx: 25
}),
Plot.ruleX([0])
]
})