chart = Plot.plot({
title: "Drought and bug infestations killed trees across the Pacific Northwest in 2022",
subtitle: "Each dot represents an area where scientists observed tree deaths",
caption: "Graphic: AP News: Caleb Diehl, Camille Fassett, Data: U.S. Forest Service",
width: Math.max(width, 500),
height: 500,
facet: {data: allDieOffs, x: 'event', label: null, marginTop: 20},
color: {scheme: 'Oranges', legend: true, label: 'Darker means more areas with damaged trees' },
projection: {type: 'mercator', domain: circle },
marks: [
Plot.geo(dougfir, { fill: 'lightgrey', facet: 'include' }),
Plot.geo(firs, { fill: 'lightgrey', facet: 'exclude' }),
Plot.density(allDieOffs, {
x: "longitude",
y: "latitude",
fx: 'event',
bandwidth: 12,
fill: "density",
weight: d => Math.log(d['ACRES'])
}),
Plot.dot(allDieOffs, {
x: "longitude",
y: "latitude",
r: 1,
fill: "#333",
}),
Plot.geo(states, { fill: 'none', strokeOpacity: .2}),
Plot.geo(nation, { strokeOpacity: 1 }),
Plot.text(states, Plot.centroid({text: (d) => d.properties.name, fill: "currentColor", stroke: "white"})),
Plot.text(["Range of\nDouglas fir"], {facet: 'include', fill: "black", textAnchor:'left', stroke: "#FFF", fontSize: '.875rem', x: -122, y: 46}),
Plot.text(["Range of white,\nsubalpine\nand grand firs"], {facet: 'exclude', fill: "black", textAnchor:'left', stroke: "#FFF", fontSize: '.875rem', x: -122, y: 46.2}),
Plot.text(["Douglas fir"], {facet: 'include', fill: "black", textAnchor:'middle', stroke: "#FFF", fontSize: '1rem', strokeWidth: 5, fontWeight: 'bold', x: -120.5, y: 47.3}),
Plot.text(["True firs"], {facet: 'exclude', fill: "black", textAnchor:'middle', strokeWidth: 5, fontWeight: 'bold', stroke: "#FFF", fontSize: '1rem', x: -120.5, y: 47.3})
]
})