chart = Plot.plot({
width: 928,
height: 550,
x: { inset: 4 },
y: { grid: true, label: "temperature (°F)" },
color: { scheme: "RdYlBu", label: "colder" },
marks: [
Plot.differenceY(weather, {
x: "date",
y1: "New York",
y2: "San Francisco",
curve: "step-after",
positiveFill: () => "NY",
negativeFill: () => "SF",
tip: true
}),
Plot.text(
weather,
Plot.selectMaxY({
x: "date",
y: "New York",
text: () => "New York",
dy: -6
})
),
Plot.text(weather, {
...Plot.selectMaxY({
x: "date",
y: "New York"
}),
y: "San Francisco",
text: () => "San Francisco",
dy: 13
}),
Plot.text(
weather,
Plot.selectMinY({
x: "date",
y: "New York",
text: () => "New York",
textAnchor: "start",
dy: -10,
dx: 6
})
),
Plot.text(weather, {
...Plot.selectMinY({
x: "date",
y: "New York",
text: () => "San Francisco"
}),
y: "San Francisco",
dy: -40
})
]
})