Plot.plot({
caption: my_graph_equation,
aspectRatio: 1,
marks: [
Plot.linearRegressionY(data, {
x: "x",
y: "y",
stroke: "steelblue",
strokeWidth: 3,
fillOpacity: cb.includes("confidence band") ? 0.1 : 0
}),
Plot.rect(data, {
x1: "x",
y1: "y",
x2: (d) => d.x - Math.sign(my_graph.a) * (d.y - my_graph.predict(d.x)),
y2: (d) => my_graph.predict(d.x),
fill: "red",
fillOpacity: 0.15
}),
cb.includes("distance")
? Plot.ruleX(data, {
x: "x",
y1: "y",
y2: (d) => my_graph.predict(d.x),
stroke: "red"
})
: null,
Plot.dot(data, { x: "x", y: "y", r: 3, fill: "red" }),
Plot.text([my_graph_equation], {
x: x_center,
y: my_graph.predict(x_center),
rotate: angle,
dy: -12,
textAnchor: "middle",
fontSize: "16px",
stroke: "white",
fill: "steelblue"
})
]
})