Skip to content

[bug] Color scheme is not customizable when using a diverging scale #9611

@hydrosquall

Description

@hydrosquall

Bug Description

When using a diverging color scale as described in the docs, the color scheme is stuck at default blueorange

Below, I unsuccessfully tried to change the color scale to redblue (editor)

Image
{
  "$schema": "https://vega.github.io/schema/vega-lite/v6.json",
  "data": {
    "values": [
      {"x": 3, "y": 30, "value": -10},
      {"x": 4, "y": 40, "value": 0},
      {"x": 5, "y": 50, "value": 10}
    ]
  },
  "mark": "bar",
  "encoding": {
    "x": {"field": "x", "type": "nominal"},
    "color": {
      "field": "value",
      "type": "quantitative",
      "scale": {"range": "diverging", "scheme": "redblue", "domainMid": 5}
    }
  }
}

Workaround: I get the intended behavior by removing "range": "diverging", and just set the custom "domainMid": 5.

Image
{
  "$schema": "https://vega.github.io/schema/vega-lite/v6.json",
  "data": {
    "values": [
      {"x": 3, "y": 30, "value": -10},
      {"x": 4, "y": 40, "value": 0},
      {"x": 5, "y": 50, "value": 10}
    ]
  },
  "mark": "bar",
  "encoding": {
    "x": {"field": "x", "type": "nominal"},
    "color": {
      "field": "value",
      "type": "quantitative",
      "scale": {
        "domainMid": 5,
        "scheme": "redblue"
      }
    }
  }
}

Potential next steps

  1. Should range: diverging be updated to allow setting a named color scheme for the range?
  2. If diverging is meant to always use this palette, does it make sense to update the docs for scale with an example of how to get a diverging color palette by choosing a diverging scheme from the collection, and setting a custom domainMid?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions