function qqnorm(data) {
const width = 640;
const height = 640;
const margin = ({top: 20, right: 40, bottom: 30, left: 40});
const qy = Float64Array.from(data).sort(d3.ascending);
const n = qy.length;
const a = n <= 10 ? 5 / 8 : 0.5;
const z = i => qnorm((i + a) / (n + 1 - 2 * a));
const x = d3.scaleLinear()
.domain([-3, 3])
.range([margin.left, width - margin.right]);
const regression = x.domain().map(
ss.linearRegressionLine(
ss.linearRegression(
Array.from(qy, (d, i) => ([z(i), d])))));
const y = d3.scaleLinear()
.domain(regression).nice()
.range([height - margin.bottom, margin.top]);
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.style("max-width", `${width}px`);
svg.append("g")
.attr("transform", `translate(0,${height - margin.bottom + 6})`)
.call(d3.axisBottom(x.copy().interpolate(d3.interpolateRound)).ticks(null, "+f"))
.call(g => g.select(".domain").remove())
.call(g => g.selectAll(".tick line").clone()
.attr("stroke-opacity", 0.1)
.attr("y1", -height))
.call(g => g.append("text")
.attr("x", width - margin.right)
.attr("y", -3)
.attr("fill", "currentColor")
.attr("font-weight", "bold")
.text("z"));
svg.append("g")
.attr("transform", `translate(${margin.left - 6},0)`)
.call(d3.axisLeft(y.copy().interpolate(d3.interpolateRound)))
.call(g => g.select(".domain").remove())
.call(g => g.selectAll(".tick line").clone()
.attr("stroke-opacity", 0.1)
.attr("x1", width));
svg.append("line")
.attr("stroke", "currentColor")
.attr("stroke-opacity", 0.3)
.attr("x1", x.range()[0])
.attr("x2", x.range()[1])
.attr("y1", y(regression[0]))
.attr("y2", y(regression[1]));
svg.append("g")
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.selectAll("circle")
.data(d3.range(n))
.join("circle")
.attr("cx", i => x(z(i)))
.attr("cy", i => y(qy[i]))
.attr("r", 3);
return svg.node();
}