variantPercentPlot = function(variant, smooth = false, facet = false, showLines = "none", showPoints = "for all"){
let variantMetric = smooth ? variant + smoothing : variant;
let metric = smooth ? variant + "_N_Gene" + smoothing : variant + "_N_Gene"
let plotObj = {
marks: [
Plot.frame({strokeWidth: 2, stroke: variantColors.get(variant)}),
Plot.ruleY([1], {strokeDasharray: "2,2"}),
showLines == "for all" ? Plot.line(deltaDataFiltered, {
filter: d => !plantstohighlight.includes(d.Plant),
x: "date",
y: d => d[metric],
stroke: facet ? "#555" : "#aaa",
z: "Plant",
strokeOpacity: facet ? .9 : .5,
}) : null,
["for all", "for highlighted locations only"].includes(showLines) ? Plot.line(deltaDataFiltered, {
filter: d => plantstohighlight.includes(d.Plant),
x: "date",
y: d => d[metric],
r: 5,
stroke: d => plantColors.get(d.Plant),
strokeOpacity: .9,
z: "Plant",
sort: d => d.date
}) : null,
showPoints == "for all" ? Plot.dot(deltaDataFiltered, {
filter: d => !plantstohighlight.includes(d.Plant),
x: "date",
y: d => d[metric],
r: 3,
fill: facet ? "#555" : "#aaa",
fillOpacity: facet ? .9 : .5,
symbol: d => d[metric] < ymax ? "circle" : "triangle",
title: d => d.Plant + "\n" + d.dateformatted + "\n" + variantMetric + " / N gene: " + d3.format(".0%")(d[metric])
}) : null,
["for all", "for highlighted locations only"].includes(showPoints) ? Plot.dot(deltaDataFiltered, {
filter: d => plantstohighlight.includes(d.Plant),
x: "date",
y: d => d[metric],
r: 5,
fill: d => plantColors.get(d.Plant),
fillOpacity: .9,
stroke: "black",
strokeWidth: 1,
symbol: d => d[metric] < ymax ? "circle" : "triangle",
title: d => d.Plant + "\n" + d.dateformatted + "\n" + variant + " / N gene: " + d3.format(".0%")(d[metric])
}) : null
],
y: {
tickFormat: d3.format(".0%"),
domain: [0, ymax],
clamp: true,
label: variantNames.get(variant) + " / N Gene" + (smoothPoints ? " (5-day trimmed mean)" : "")
},
x: {
label: "date of sample taken →"
},
width: chartWidth,
height: chartWidth * .5,
};
if(facet){
plotObj.facet = {
data: deltaDataFiltered,
y: "Plant",
label: null,
marginRight: 24
};
plotObj.fy = {
padding: .2,
tickRotate: 90,
};
plotObj.marginRight = 20;
plotObj.width = Math.min(width / 2.2, 600);
plotObj.height = plantstoshow.length * 220;
};
return Plot.plot(plotObj)
}