(Possibly a duplicate of #1121, but I'm not 100% sure!)
When I make a barchart in which the stacking channel (fill or color) is ordinal, it can be tricky to get the legend and the stacking order to line up. Although there are many cases where simple alphanumerical order or frequency is the right call, often (especially with survey responses) it's easier to just list out the levels.
I had assumed that if I provided an array of values to color.domain (which orders the legend glyphs), the stacking order would reflect this.
I imagine there are cases where you do still want to stack by frequency even when your legend is ordered (and sort can ), but I think if you provide the same channel to both fill/color and sort, users would benefit from Plot using any levels provided by color.domain. The workaround is to provide a sorting function that re-uses those levels, but I think this is a common enough scenario that it would be helpful for Plot to default to this behaviour.
The solution is to use order: freqLevels. ("If an array of z values are specified, they should enumerate the z values for all series in the desired order")
(Possibly a duplicate of #1121, but I'm not 100% sure!)
When I make a barchart in which the stacking channel (
fill
orcolor
) is ordinal, it can be tricky to get the legend and the stacking order to line up. Although there are many cases where simple alphanumerical order or frequency is the right call, often (especially with survey responses) it's easier to just list out the levels.I had assumed that if I provided an array of values to
color.domain
(which orders the legend glyphs), the stacking order would reflect this.I imagine there are cases where you do still want to stack by frequency even when your legend is ordered (and
sort
can ), but I think if you provide the same channel to bothfill
/color
andsort
, users would benefit from Plot using any levels provided bycolor.domain
. The workaround is to provide a sorting function that re-uses those levels, but I think this is a common enough scenario that it would be helpful for Plot to default to this behaviour.Here's an example notebook:
https://observablehq.com/@jimjamslam/stack-a-barchart-on-ordinal-data
Thank you!