Plot.plot({
marks: [
Plot.lineY(stocks, {
x: "Date",
y: "Close",
stroke: "symbol",
opacity: 0.3,
tip: true
}),
Plot.lineY(
stocks,
Plot.windowY(
{ k: 50, anchor: "middle", reduce: "mean", strict: true },
{ x: "Date", y: "Close", stroke: "symbol" }
)
),
Plot.text(
stocks, Plot.selectLast({x: "Date", y: "Close", text: "symbol", fill: "symbol", dx: 15, fontSize: 18})),
Plot.tip([`Oct 27, 2022: Elon Musk becomes Twitter CEO`],
{x: new Date('2022-10-27'), y: 250, anchor: "bottom-left"}
)
],
color: { legend: true, range: ["teal", "navy", "orange"] },
y: { label: "Closing Price (USD)" },
marginRight: 100
})