plt = Plot.plot({
width: 800, // or a dynamic value based on `width` variable
height: 600,
style: {fontSize: "16px"},
color: {
legend: false
},
x: {
label: "t-statistic",
axis: true,
domain: [-10,10]
},
y: {
axis: false,
domain: [0,max_y]
},
marks: [
Plot.ruleY([0]),
Plot.line(pdfdata, {filter: d => d.dist == "student-t" && d.type == "pdf", x: "x", y: "pdf", stroke : "dist", strokeWidth: 2}),
Plot.areaY(pdfdata, {filter: d => showpvalue && side == "left" && d.x <= tobs &&
d.dist == "student-t" && d.type == "pdf", x: "x", y: "pdf", fill: "orange", opacity: 0.5}),
Plot.areaY(pdfdata, {filter: d => showpvalue && side == "right" && d.x >= tobs &&
d.dist == "student-t" && d.type == "pdf", x: "x", y: "pdf", fill: "orange", opacity: 0.5}),
Plot.areaY(pdfdata, {filter: d => showpvalue && side == "both" && d.x <= -Math.abs(tobs) &&
d.dist == "student-t" && d.type == "pdf", x: "x", y: "pdf", fill: "orange", opacity: 0.5}),
Plot.areaY(pdfdata, {filter: d => showpvalue && side == "both" && d.x >= Math.abs(tobs) &&
d.dist == "student-t" && d.type == "pdf", x: "x", y: "pdf", fill: "orange", opacity: 0.5}),
Plot.dot([{x: tobs, y: 0}], {x: "x", y: "y", fill: conclusioncolor, symbol: "circle", r: 5}),
Plot.arrow([{x1: tobs, y1: max_y/12, x2:tobs, y2: 0.01}], {x1: "x1", y1: "y1", x2: "x2", y2: "y2", stroke: conclusioncolor}),
Plot.text([{x1: tobs, y1: bignudge*max_y/12, texter: "t(obs)"}], {x: "x1", y: "y1", text: "texter", fontSize: textfontsize}),
Plot.ruleX([{x: tcrit, y: max_y/4}], {filter: d => showcrit && side == "both", x: "x", y: "y", fill: "green"}),
Plot.ruleX([{x: -tcrit, y: max_y/4}], {filter: d => showcrit && side == "both", x: "x", y: "y", fill: "green"}),
Plot.text([{x1: tcrit, y1: nudge*max_y/4, texter: "t(crit)"}],
{filter: d => showcrit && side == "both",x: "x1", y: "y1", text: "texter", fontSize: textfontsize}),
Plot.text([{x1: -tcrit, y1: nudge*max_y/4, texter: "-t(crit)"}],
{filter: d => showcrit && side == "both",x: "x1", y: "y1", text: "texter", fontSize: textfontsize}),
Plot.ruleX([{x: tcrit, y: max_y/4}], {filter: d => showcrit && side == "right", x: "x", y: "y", fill: "green"}),
Plot.text([{x1: tcrit, y1: nudge*max_y/4, texter: "t(crit)"}],
{filter: d => showcrit && side == "right",x: "x1", y: "y1", text: "texter", fontSize: textfontsize}),
Plot.ruleX([{x: -tcrit, y: max_y/4}], {filter: d => showcrit && side == "left", x: "x", y: "y", fill: "green"}),
Plot.text([{x1: -tcrit, y1: nudge*max_y/4, texter: "-t(crit)"}],
{filter: d => showcrit && side == "left",x: "x1", y: "y1", text: "texter", fontSize: textfontsize}),
Plot.arrow([{x1: tcrit*bignudge, y1: max_y/6, x2:10, y2: max_y/6}], {filter: d => showcrit && side == "right",
x1: "x1", y1: "y1", x2: "x2", y2: "y2", stroke: "red"}),
Plot.arrow([{x1: -tcrit*bignudge, y1: max_y/6, x2:-10, y2: max_y/6}], {filter: d => showcrit && side == "left",
x1: "x1", y1: "y1", x2: "x2", y2: "y2", stroke: "red"}),
Plot.arrow([{x1: tcrit*bignudge, y1: max_y/6, x2:10, y2: max_y/6}], {filter: d => showcrit && side == "both",
x1: "x1", y1: "y1", x2: "x2", y2: "y2", stroke: "red"}),
Plot.arrow([{x1: -tcrit*bignudge, y1: max_y/6, x2:-10, y2: max_y/6}], {filter: d => showcrit && side == "both",
x1: "x1", y1: "y1", x2: "x2", y2: "y2", stroke: "red"}),
Plot.text([{x1: (-10 - tcrit*bignudge)/2, y1: max_y/4, texter: "Reject H₀"}],
{filter: d => showcrit && side == "left", x: "x1", y: "y1", text: "texter", fontSize: textfontsize}),
Plot.text([{x1: (10 + tcrit*bignudge)/2, y1: max_y/4, texter: "Reject H₀"}],
{filter: d => showcrit && side == "right", x: "x1", y: "y1", text: "texter", fontSize: textfontsize}),
Plot.text([{x1: (-10 - tcrit*bignudge)/2, y1: max_y/4, texter: "Reject H₀"}],
{filter: d => showcrit && side == "both", x: "x1", y: "y1", text: "texter", fontSize: textfontsize}),
Plot.text([{x1: (10 + tcrit*bignudge)/2, y1: max_y/4, texter: "Reject H₀"}],
{filter: d => showcrit && side == "both", x: "x1", y: "y1", text: "texter", fontSize: textfontsize})
]
})