Search code examples
vegavega-lite

Vega lite - accessing 'repeat' variable to use as filter


I'm attempting to make a trellis bar chart, with the grand total shown faintly behind each chart - see this image.

enter image description here

I've successfully managed to create this a verbose spec, but I want to make this more succinct, by using 'repeat' with a filter. Here is the working version.

Here is my version which almost works, but I can't work out how to allow the filter to access the 'repeat' variable.

How can I access the variable specified in 'repeat' to correctly filter the data?

I have tried the following but it doesn't work

 { 
  "transform": [
     {"filter": "datum.gender == repeat"}
   ]
 }

Solution

  • This is not supported right now: https://github.com/vega/vega-lite/issues/2518. These kinds of use cases where you can reuse parts will work much better in DSLs like Altair. JSON is unfortunately not a good fit for reuse. As a side note, a succinct spec is not faster than the verbose spec you wrote. However, I understand that it would be easier to read. Another related proposal for shorter specs is: https://github.com/vega/vega-lite/issues/3384.