regression_mark_with_legend = Plot.plot({
width: 800,
height: 500,
marks: [
Plot.dot(cars, {
x: "weight (lb)",
y: "power (hp)",
strokeOpacity: 0.5,
r: 2
}),
Plot.linearRegressionY(cars, {
x: "weight (lb)",
y: "power (hp)",
stroke: d3.schemeCategory10[1],
fill: d3.schemeCategory10[0],
fillOpacity: 0.3,
ci: 0.999
}),
Plot.ruleX([1610]),
Plot.ruleY([45]),
Plot.line(
[
[4000, 80],
[4200, 80]
],
{ stroke: d3.schemeCategory10[1] }
),
() => svg`
<g transform="translate(${595} ${377}) scale(1.3)">
${MathJax.tex2svg(String.raw`ax+b`).querySelector("svg")}
</g>`,
Plot.rect([{ x1: 4000, x2: 4200, y1: 65, y2: 73 }], {
x1: "x1",
x2: "x2",
y1: "y1",
y2: "y2",
fill: d3.schemeCategory10[0],
opacity: 0.3
}),
() => svg`
<g transform="translate(${595} ${406}) scale(1.3)">
${MathJax.tex2svg(
String.raw`\text{K. I. } \mu(x_0) = \alpha x + \beta`
).querySelector("svg")}
</g>`,
Plot.line(
[
[3900, 60],
[5000, 60],
[5000, 87],
[3900, 87],
[3900, 60]
],
{ stroke: "black", strokeWidth: 2 }
)
]
})