zylatis
zylatis

Reputation: 478

Order stacked Vega Lite bar graph by specific order

I have the following VL chart and I wish to specify that the ordering of the stacks match the order of the domain given.

I've had a look and I see some examples where ordering of nominal axes can be done by passing a list to sort, but I can't seem to find similar logic for colour stacks.

I understand how to order based on some quantitative variable, and clearly the ordering by 'metric' label here is just doing it alphabetically, but I would like to avoid having to add extra columns to the data if possible and just specify it in the VL itself.

Upvotes: 2

Views: 1211

Answers (1)

jakevdp
jakevdp

Reputation: 86310

Sorting stacked fields by a specific order (rather than according to a data field, as you've done in your example) is not supported in Vega-Lite. The relevant feature request is here: https://github.com/vega/vega-lite/issues/1734

A workaround is to use a calculate transform to encode the desired order. A simple example of this can be found here: https://vega.github.io/vega-lite/docs/stack.html#order

Upvotes: 1

Related Questions