lineplot_stocksv2 =
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",
textAnchor: "start",
dx: 5,
dy: -9,
fontSize: 15
})
),
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"] },
x: {
domain: [new Date("2019-01-01"), new Date("2024-06-04")]
},
y: {
domain: [0, 400],
label: "Closing Price (USD)"
},
marginRight: 100
})