Number of classes for discrete color classes (for quantile or quantize scheme)
See original GitHub issueGiven a simple bar chart with embedded data, for which I like to color encode the values using a quantize type scale (VL-docs):
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{"a": "A", "b": 28},
{"a": "B", "b": 55},
{"a": "C", "b": 43},
{"a": "D", "b": 91},
{"a": "E", "b": 81},
{"a": "F", "b": 53},
{"a": "G", "b": 19},
{"a": "H", "b": 87},
{"a": "I", "b": 52}
]
},
"mark": "bar",
"encoding": {
"x": {"field": "a", "type": "nominal", "axis": {"labelAngle": 0}},
"y": {"field": "b", "type": "quantitative"},
"color": {
"field": "b",
"type": "quantitative",
"scale": {"type": "quantize", "scheme": "purples"}
}
}
}
Open the Vega-Lite Chart in the Vega Editor
I observe the default uses 5 classes for scale type quantize, but how to change the number of classes? Let’s say I want to use the color scheme purples to use 3 classes.
At the color scale page, I observe there is a discrete color schemes for purples:
But how to use these? Defining purples-3 for scheme does not work.
In Vega it would be possible to define a count as part of the scheme within range:
{
"name": "color",
"type": "quantize",
"range": {"scheme": "purples", "count": 3},
"domain": {"data": "values", "field": "b"}
}
Open the Vega Chart in the Vega Editor
As you can see, this successfully use 3 classes for the quantize scale. But how to approach this in Vega-Lite?
Maybe it is a regression and the style of purples-3 worked before? Since I see in this obs-notebook in the selection list of Sequential Multi-Hue Schemes it was defined as such that the suffix indicates the desired number of colors.
In this obs-notebook I observe they use range: d3.schemeBlues[9], but "scheme": "purples[3]" won’t work either.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)

Top Related StackOverflow Question
Thanks! That is what I need indeed! I was close, but still too far…
You need a scheme parameter object . I think this is what you want.
Editor