Plot.plot({
marks: [
Plot.dot(scoresCombined, {
x: "PC1",
y: "PC2",
fill: "watershed",
r: 4,
opacity: 0.85,
stroke: "black",
strokeOpacity: 0.8,
tip: true
}),
Plot.arrow(loadings, {
x1: 0,
x2: (d) => d.PC1 * scalingFactor,
y1: 0,
y2: (d) => d.PC2 * scalingFactor
}),
Plot.text(loadings, {
x: (d) => d.PC1 * scalingFactor,
y: (d) => d.PC2 * scalingFactor,
text: "Variable",
dy: -5,
dx: 30,
fill: "black",
stroke: "white"
})
],
color: { legend: true }
})