Published
Edited
Jan 1, 2022
1 fork
Importers
15 stars
Also listed in…
Plot Experiments
Insert cell
Insert cell
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
})
Insert cell
function hatchPlot(plot) {
const textures = plot.color?.range?.slice();

if (textures) {
plot.color.range.forEach((texture, i) => texture.url && (plot.color.range[i] = texture.url()));
}
plot = Plot.plot(plot);

if (textures) {
for (const texture of textures) {
if (texture.apply) d3.select(plot).call(texture);
}
}

return plot;
}
Insert cell
data = FileAttachment("data.json").json()
Insert cell
textures = require("textures")
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