Plot.plot({
marginLeft: 300,
x: {
domain: customXDomain,
},
marks: [
Plot.ruleX([0]),
Plot.barX(data, {
x: (d) => customXDomain[1],
y: "Response_in_Text",
fill: "slategrey",
opacity: 0.25,
}),
Plot.barX(data, {
x: "count",
y: "Response_in_Text",
sort: { y: "x", reverse: true },
}),
Plot.text(data, {
x: (d) => customXDomain[1],
y: "Response_in_Text",
text: (d) => `${((d.count / customXDomain[1]) * 100).toFixed(0)}%`,
dx: -5,
textAnchor: "end",
fill: "black",
}),
Plot.axisX({
ticks: tickArray,
tickFormat: (d) => `${((d / customXDomain[1]) * 100).toFixed(0)}%`,
}),
],
})