chart = hatchPlot({
color: {
range: [
textures.circles().size(4),
textures.lines().orientation("3/8").size(7).strokeWidth(0.25)
]
},
x: {
tickFormat: (d) => d3.format("~s")(Math.abs(d)),
label: "←male female→ (thousands)",
nice: true,
round: true
},
y: {
domain: d3.groupSort(
data,
(v) => parseInt(v[0].age),
(d) => d.age
),
reverse: true
},
marginLeft: 60,
marks: [
Plot.barX(data, {
x: (d) => d["population"] * (1 - 2 * (d["sex"] === "male")),
y: "age",
fill: "sex",
inset: 2
}),
Plot.barX(data, {
x: (d) => d["population"] * (1 - 2 * (d["sex"] === "male")),
y: "age",
stroke: "black"
})
],
height: width * 0.9
})