Skip to content

Feature request: detect ordinal domain in color when ordering by same channel #2000

@jimjam-slam

Description

@jimjam-slam

(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.

Here's an example notebook:

https://observablehq.com/@jimjamslam/stack-a-barchart-on-ordinal-data

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions