{
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: phobias, y: "Question" },
color: { domain: order, scheme: "RdBu" , legend: true},
marks: [
Plot.barX(
phobias,
Plot.groupZ(
{ x: normalize ? "proportion-facet" : "count" },
{
fill: "Response",
stroke: "#777",
strokeWidth: 0.5,
order,
offset
}
)
),
Plot.textX(
phobias,
Plot.stackX(
Plot.groupZ(
{ x: normalize ? "proportion-facet" : "count", text: "first" },
{
text: (d) => d.Response.replace(/[^A-Z]/g, ""),
z: "Response",
order,
offset
}
)
)
),
],
marginLeft: 120,
title: "Do you have a phobia of...",
subtitle: "#30DayChartChallenge Day 27 - Good/Bad",
caption: "https://observablehq.com/@dddanieltan/30daychartchallenge-day27-good-bad",
width: 800,
height: 300,
});
}