Plot.plot({
color: {
legend: true,
domain: includeCounties.map(d => d.key),
range: includeCounties.map(d => d.color),
},
x: {
interval: 1,
tickFormat: '.0f',
ticks: [2010, 2015, 2020, 2023]
},
y: {
tickFormat: '.1%',
label: 'Population growth',
grid: true,
domain: [0, 0.04]
},
marks: [
Plot.lineY(counties.filter(d => d.county === 'Montana'), {
x: "year",
y: "change",
stroke: "county",
strokeWidth: 1.5,
strokeDasharray: [2, 3],
curve: 'step'
}),
Plot.areaY(counties.filter(d => d.county !== 'Montana'), {
x: "year",
y: "change",
fill: "county",
fx: d => (includeCounties.map(d => d.key).indexOf(d.county)-1) % 3,
fy: d => Math.floor((includeCounties.map(d => d.key).indexOf(d.county)-1) / 3),
opacity: 0.5,
curve: 'step'}),
Plot.lineY(counties.filter(d => d.county !== 'Montana'), {
x: "year",
y: "change",
stroke: "county",
fx: d => (includeCounties.map(d => d.key).indexOf(d.county)-1) % 3,
fy: d => Math.floor((includeCounties.map(d => d.key).indexOf(d.county)-1) / 3),
strokeWidth: 3,
curve: 'step'}),
Plot.ruleY([0]),
Plot.text(counties.filter(d => d.county !== 'Montana' && d.year === '2023'), {
x: "year",
y: "change",
text: d => `${d3.format('+.1%')(d.change)}`,
dy: -10,
fx: d => (includeCounties.map(d => d.key).indexOf(d.county)-1) % 3,
fy: d => Math.floor((includeCounties.map(d => d.key).indexOf(d.county)-1) / 3)
})
],
})