collegeScatterRows = countyOrder.flatMap(c => {
const syn = synthCollege.find(d => d.COUNTYFP === c);
if (!syn) return [];
const ushe = realCountyTotals.find(d => d.COUNTYFP === c)?.ushe_enrollment;
const ipeds = d3.sum(realCollegeLevel.filter(d => d.COUNTYFP === c && ipedsInScope(d)), d => d.nces_enrollment);
const enrolledSyn = syn.undergraduate + syn.graduate;
const name = countyName[c];
return [
{reference: "USHE AY 2025", measure: "Enrolled", x: ushe, y: enrolledSyn, county: name},
{reference: "USHE AY 2025", measure: "Population", x: ushe, y: syn.age_18_24, county: name},
{reference: "IPEDS fall 2023", measure: "Enrolled", x: ipeds, y: enrolledSyn, county: name},
{reference: "IPEDS fall 2023", measure: "Population", x: ipeds, y: syn.age_18_24, county: name}
].filter(d => d.x != null);
});
collegeScatterMax = d3.max(collegeScatterRows, d => Math.max(d.x, d.y));
collegeDiagRows = ["USHE AY 2025", "IPEDS fall 2023"].flatMap(reference =>
["Enrolled", "Population"].flatMap(measure => [
{reference, measure, x: 0, y: 0},
{reference, measure, x: collegeScatterMax, y: collegeScatterMax}
])
);
Plot.plot({
width: 760,
height: 640,
grid: true,
style: {background: "transparent", color: "inherit"},
fx: {label: null},
fy: {label: null},
x: {label: "Reference (students)", grid: true},
y: {label: "Synthetic (persons)", grid: true},
marks: [
Plot.line(collegeDiagRows, {x: "x", y: "y", fx: "measure", fy: "reference", stroke: "#999", strokeDasharray: "4 4"}),
Plot.dot(collegeScatterRows, {
x: "x", y: "y", fx: "measure", fy: "reference",
fill: "#1f78b4", r: 5, tip: tipTheme, title: d => d.county
})
]
})