Public
Edited
Mar 14, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
y: {
grid: true,
inset: 6
},
marks: [
Plot.boxY(selectedData, {
x: (d) => `[${selectProvince}] ` + d.gender,
y: "birthYear",
stroke: "gender"
}),
Plot.boxY(data, {
x: (d) => "[ 全国 ] " + d.gender,
y: "birthYear",
stroke: "gender"
})
]
})
Insert cell
Plot.plot({
grid: { x: true, y: true },
color: {
legend: true
// scheme: "bupu",
// type: "symlog"
},
// facet: { data: data, x: "gender", marginRight: 90 },
marks: [
Plot.boxX(data, {
y: "province",
x: "birthYear",
stroke: "gender",
r: (d) => (d.gender === "男" ? 1 : 2)
}) //Plot.bin({ fill: "count" }, { x: "province", y: "ethnic" }))
]
})
Insert cell
Plot.plot({
grid: { x: true, y: true },
color: {
legend: true
// scheme: "bupu",
// type: "symlog"
},
marks: [
Plot.boxX(data, {
y: "ethnic",
x: "birthYear",
stroke: "gender",
r: (d) => (d.gender === "男" ? 1 : 2)
}) //Plot.bin({ fill: "count" }, { x: "province", y: "ethnic" }))
]
})
Insert cell
Insert cell
ethnics = {
const collection = new Array(...new Set(data.map((d) => d.ethnic)));
collection.reverse();
collection.push("--");
collection.reverse();
return collection;
}
Insert cell
provinces = {
const collection = new Array(...new Set(data.map((d) => d.province)));
collection.reverse();
collection.push("--");
collection.reverse();
return collection;
}
Insert cell
data = {
return dataWithBirthYear.map((d) => {
d.birthYear = d.birthYear < 1990 ? d.birthYear : undefined;
return d;
});
}
Insert cell
table-with-birthYear.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
d3 = require("d3")
Insert cell
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