inRange = (start, end) => {
const data = philip.filter((a) => a.DATE >= start && a.DATE <= end);
const { rSquared } = d3regression
.regressionLinear()
.x((d) => d.UNRATE)
.y((d) => d.CPIAUCSL)(data);
const options = {
x: "UNRATE",
y: "CPIAUCSL",
r: 2,
stroke: "steelblue",
title: "DATE"
};
return Plot.plot({
color: {
legend: true
},
grid: true,
inset: 15,
marginLeft: 50,
title: `Unemployment vs. CPI % change from year ago: ${new Date(
start
).getFullYear()} - ${new Date(end).getUTCFullYear()}`,
subtitle: tex`R^2 = ${rSquared.toFixed(2)}`,
marks: [
Plot.frame(),
Plot.dot(data, { ...options, tip: true }),
Plot.linearRegressionY(data, { ...options, stroke: "green" }),
Plot.crosshair(data, options)
]
});
}