Plot.plot({
x: {
label: "Oct-Nov Precipitation (inches)",
},
y: {
label: "Wateryear (Oct-Sep) Precipitation (inches)",
},
marks: [
Plot.frame(),
Plot.dot(data, {
y: "y",
x: "x",
r: 4,
fill: "#ddd",
title: (d) => dateFormat(d.date),
}),
Plot.dot(data.filter(({ date }) => date.getUTCFullYear() >= 2000), {
y: "y",
x: "x",
r: 4,
stroke: "#888888",
title: (d) => dateFormat(d.date),
}),
Plot.text(data.filter(({ date }) => date.getUTCFullYear() >= 2000 && !elninoYears.includes(date.getUTCFullYear())), {
y: "y",
x: "x",
text: (d) => `${d.date.getUTCFullYear()}`,
dx: -6,
dy: -1,
fill: "#888888",
textAnchor: "end",
}),
Plot.ruleX([options.find(d => d.id === "octnov").base_value], {
stroke: "#377eb8",
strokeDasharray: 4,
}),
Plot.text([options.find(d => d.id === "octnov")], {
y: (d) => d.base_value,
text: (d) => `${d.base_period} Oct+Nov\nAverage ${d.base_value} inches`,
dx: -60,
dy: -15,
textAnchor: "start",
}),
Plot.ruleY([options.find(d => d.id === "wateryear").base_value], {
stroke: "#377eb8",
strokeDasharray: 4,
}),
Plot.text([options.find(d => d.id === "wateryear")], {
y: (d) => d.base_value,
text: (d) => `${d.base_period} Wateryear\nAverage ${d.base_value} °F`,
dx: 285,
dy: -10,
textAnchor: "end",
}),
Plot.dot(data.filter(({ date }) => elninoYears.includes(date.getUTCFullYear())), {
y: "y",
x: "x",
r: 4,
stroke: "blue",
}),
Plot.text(data.filter(({ date }) => elninoYears.includes(date.getUTCFullYear())), {
y: "y",
x: "x",
text: (d) => `${d.date.getUTCFullYear()}\nEl Nino`,
dx: -6,
dy: -1,
fill: "blue",
textAnchor: "end",
}),
Plot.areaY(intervalData, {
x: "x", y1: "left", y2: "right",
fill: "#a65628",
fillOpacity: 0.3,
}),
Plot.line(intervalData, {
x: "x",
y: d => predict(d.x),
stroke: "#a65628",
strokeWidth: 2,
}),
]
})