{
const { order, offset } = Likert([
["Strongly Disagree", -1],
["Disagree", -1],
["Neutral", 0],
["Agree", 1],
["Strongly Agree", 1]
]);
return Plot.plot({
x: normalize
? { tickFormat: "%", label: "answers (%)" }
: { tickFormat: Math.abs, label: "# of answers" },
y: { tickSize: 0 },
facet: { data: survey, y: "Question" },
color: { domain: order, scheme: "RdBu" },
marks: [
Plot.barX(
survey,
Plot.groupZ(
{ x: normalize ? "proportion-facet" : "count" },
{
fill: "Response",
stroke: "#777",
strokeWidth: 0.5,
order,
offset
}
)
),
Plot.textX(
survey,
Plot.stackX(
Plot.groupZ(
{ x: normalize ? "proportion-facet" : "count", text: "first" },
{
text: (d) => d.Response.replace(/[^A-Z]/g, ""),
z: "Response",
order,
offset
}
)
)
)
]
});
}