Public
Edited
Jul 11, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
var threshold = 1e10;

if (select === "Total") threshold = basic.collegeTotal;
if (select === "985211") threshold = basic.college985211;
if (select === "985") threshold = basic.college985;

const data = highSchoolEveryScore.filter((d) => d.accumulate < threshold);

const plt = Plot.plot({
grid: true,
x: { nice: true, reverse: true },
y: { nice: true },
color: { legend: true, nice: true },
marks: [
Plot.dot(data, {
x: "score",
y: "accumulate",
fill: "ratio"
}),
Plot.ruleY([basic.collegeTotal]),
Plot.ruleY([basic.college985211]),
Plot.ruleY([basic.college985]),
Plot.frame()
]
});

return plt;
}
Insert cell
highSchoolEveryScore = highSchoolData.highSchoolEveryScore
Insert cell
highSchoolEveryScore
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
highSchoolData = {
var dataUrban = dataEveryScore.filter(
(d) => (d.pos === "Urban") & (d.accumulate < basic.forUrban)
),
dataSuburb = dataEveryScore.filter(
(d) => (d.pos === "Suburb") & (d.accumulate < basic.forSuburb)
);

var scores = [
...new Set(
dataUrban.map((d) => d.score).concat(dataSuburb.map((d) => d.score))
)
];

const highSchoolEveryScore = [];

var urban, suburb, score;
scores.map((score) => {
urban = dataUrban.filter((d) => d.score === score)[0];
suburb = dataSuburb.filter((d) => d.score === score)[0];

urban = urban ? urban.num : 0;
suburb = suburb ? suburb.num : 0;

highSchoolEveryScore.push({
score,
urban,
suburb,
total: urban + suburb,
ratio: suburb === 0 ? undefined : urban / suburb
});
});

highSchoolEveryScore.map((d) => {
score = d.score;
Object.assign(d, {
accumulate: d3.sum(
highSchoolEveryScore.filter((d) => d.score >= score),
(d) => d.total
)
});
});

return { dataUrban, dataSuburb, scores, highSchoolEveryScore };
}
Insert cell
dataEveryScore = {
const data = [];

["Urban", "Suburb", "Total"].map((pos) => {
rawData.map((d) => {
var highSchool = true;

if (pos === "Urban") highSchool = d["nUrban"] < basic.forUrban;
if (pos === "Suburb") highSchool = d["nSuburb"] < basic.forSuburb;

data.push({
score: d.Segment,
num: d["d" + pos],
accumulate: d["n" + pos],
ratio: d["ratio" + pos],
pos,
highSchool
});
});
});

return data;
}
Insert cell
dataEveryScore
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
basic = {
const { sumTotal, sumUrban, sumSuburb } = rawData[0];

const forTotal = 8867,
forUrban = 22230 + parseInt(forTotal / 2),
forSuburb = 45893 + parseInt(forTotal / 2);

const collegeTotal = 32960,
college985 = 3496,
college985211 = college985 + 4586;

return {
sumTotal,
sumUrban,
sumSuburb,
forUrban,
forSuburb,
collegeTotal,
college985,
college985211
};
}
Insert cell
Insert cell
Insert cell
numbers@2.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

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