Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bar stack order does not respect domain order when based on colour channel #9496

Open
claresloggett opened this issue Dec 12, 2024 · 1 comment
Labels

Comments

@claresloggett
Copy link

Bug Description

If create a bar chart, and set the color channel to a field, I will get a stacked bar chart like so:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {"values": [{"category": "Cat1", "status": "Present"},
    {"category": "Cat1", "status": "Present"},
    {"category": "Cat1", "status": "Missing"},
    {"category": "Cat1", "status": "Present"},
    {"category": "Cat2", "status": "Present"},
    {"category": "Cat2", "status": "Present"},
    {"category": "Cat2", "status": "Present"},
    {"category": "Cat2", "status": "Missing"},
    {"category": "Cat2", "status": "Missing"},
    {"category": "Cat2", "status": "Present"}]},
  "encoding": {
    "x": {"aggregate": "count"},
    "y": {"field": "category"},
    "color": {"field": "status",
      "scale": {
        "domain": ["Present","Missing"], 
        "range": ["blue", "lightgrey"]
      }
    },
  },
  "mark": {"type": "bar", "tooltip": true}
}
Image

Open the Chart in the Vega Editor

Here I have set the domain of the colour channel. The order of the values [Present, Missing] is reflected in the legend as a result. However, the order of the stacked bars themselves is unchanged. The order of the stacked bars will always have "Missing" nearest the axis, regardless of domain order - presumably it is ordering the values alphabetically. In this case I would like "Present" to be the bar value nearest the axis.

Is this expected behaviour? The docs I found said that the stack order defaults to the stack grouping field, so I would have expected setting the domain on the channel to affect the default stack order.

Checklist

- [ x] I checked for duplicate issues.
@MarcBaeuerle
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants