Plot.plot({
height: 750,
width:300,
margin:64,
color: {
domain: [ ,,,...order],
scheme: "rdylbu",
invert: true
},
y: {
label: "exports (US$, billions) →",
axis: null ,
domain:[180,0]
},
x: {
inset: 16,
ticks: [2019, 2020],
domain:[2019,2020],
axis:"top",
tickFormat: (d) => parseInt(d),
label: null,
invert: true
},
marks: [
Plot.areaY(
exports,
Plot.stackY({
y: "total",
x: "year",
fill: "country",
order,
fillOpacity: 0.7,
stroke: "white"
})
),
Plot.rectY(
exports,
Plot.stackY({
y: "total",
x: "year",
z: "country",
order,
x2: "year",
x1: (d) => +d["year"] + 0.25 * Math.sign(d["year"] - 2019.5),
fill: "country",
stroke: "white",
title: (d) => `${d["total"]} billion US$, ${d["share"]}`
})
),
Plot.text(
exports,
Plot.stackY(
Plot.groupZ(
{ y: "mean", text: "first" },
{
y: "total",
z: "country",
order,
x: 2019.5,
text: "country"
}
)
)
)
]
})