Plot.plot({
height: 500,
title: "Estimate by Age and Income",
y: {
grid: true,
label: "Estimate",
tickFormat: d => `${Math.round(d * 100)}%`
},
x: {
grid: true,
label: "Age"
},
color: {
type: "ordinal",
legend:true,
domain: ["Low Income", "Mid Income", "High Income"],
range: ["purple", "gray", "#51de63"]
},
facet: {
data: data,
x: "Sex"
},
marks: [
Plot.areaY(data, {
x: "Age",
y1: "conf.low",
y2: "conf.high",
fill: "Income3",
fillOpacity: 0.3,
title: d => `Income: ${d.Income3}\nEstimate: ${(d.estimate * 100).toFixed(2)}%\nAge: ${d.Age}`
}),
Plot.line(data, {
x: "Age",
y: "estimate",
stroke: "Income3",
title: d => `Income: ${d.Income3}\nEstimate: ${(d.estimate * 100).toFixed(2)}%\nAge: ${d.Age}`
})
]
});