-
A horizontal stacked bar chart has two sort directions:
I'm trying to sort the segments by a custom order (the same that is applied to the legend) Can I do this with Plot, or do I need to sort the dataset? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Can you make the notebook public so we can see? Thanks. |
Beta Was this translation helpful? Give feedback.
-
You want to use the order option to the stack transform (rather than the sort option). If you want to sort the segments in ascending order based on the z channel (which defaults to fill), that’s: Plot.plot({
marginLeft: 400,
color: {
domain: ["1", "2", "3", "4", "5"],
range: ["grey", "orange", "red", "pink", "black"],
legend: true
},
marks: [
Plot.barX(dataset, {
y: data.accessors.y,
x: data.accessors.x,
fill: data.accessors.z,
order: "z",
sort: {
y: "-x"
}
})
]
}) If you want to specify a different order of z values, then you could specify the order option as a list of values in the desired order, e.g., |
Beta Was this translation helpful? Give feedback.
You want to use the order option to the stack transform (rather than the sort option). If you want to sort the segments in ascending order based on the z channel (which defaults to fill), that’s:
If you want to specify a different order of z values, then you could specify the order option as a list of values in the desired order, e.g.,
["1", "2",…