Search code examples
bar-chartvega-litevega

Splitting the color legend in a repeat spec in vega


I am using a dataset with the following columns: date, counts, country, engine, and type.

I have created a view with three charts using the repeat operator. The charts show dates on the X axis, counts on Y, and then the bars are split by either country, engine, or type.

I am happy with how things look but I would like to have three separate color legends, one for each domain (so a legend for countries, a legend for type, and a legend for engine). How do I do that?

Here is the link to the editor.


Solution

  • To have independent color scales & legends, add the following at the top level of the chart specification:

    "resolve": {"scale": {"color": "independent"}}
    

    For more information, see https://vega.github.io/vega-lite/docs/resolve.html.