Published
Edited
Jul 22, 2022
1 star
Insert cell
Insert cell
Plot.plot({
x: { tickFormat: Math.abs, label: "# of answers" },
y: { tickSize: 0 },
color: { domain: likert.order, scheme: "RdBu", legend: true },
marks: [
Plot.barX(
survey,
Plot.groupY(
{ x: "count" },
{ y: "Question", fill: "Response", ...likert }
)
),
Plot.ruleX([0])
]
})
Insert cell
likert = Likert([
["Strongly Disagree", -1],
["Disagree", -1],
["Neutral", 0],
["Agree", 1],
["Strongly Agree", 1]
])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
sign = (label) => label.match(/neutral/i) ? 0 : label.match(/disagree/i) ? -1 : 1
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function Likert(responses) {
const map = new Map(responses);
return {
order: Array.from(map.keys()),
offset(facetstacks, X1, X2, Z) {
for (const stacks of facetstacks) {
for (const stack of stacks) {
const k =
d3.sum(stack, (i) => (X2[i] - X1[i]) * (1 - map.get(Z[i]))) / 2;
for (const i of stack) {
X1[i] -= k;
X2[i] -= k;
}
}
}
}
};
}
Insert cell
Insert cell
survey = FileAttachment("survey.json").json()
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more