1

I've been working with Vega-Lite to build a complex, faceted visualization. However, I've encountered an issue that, as far as I'm aware, is known within the community. I am trying to make a faceted chart with columns based on a category in my data. Each column should have bars corresponding to different measures, which are represented by rows. Furthermore, each bar should have an independent scale on the X axis. However, the number of measures varies per category. The issue is that Vega-Lite displays the same number of rows in each column, even if there is no data available for some measures in certain categories. In other words, the facet grid is calculated prior to any data filtering being applied and it remains constant, leading to some facets having an excessive number of empty rows.

What I am hoping to achieve is that each facet is independent not only in terms of the X axis scale, but also in terms of the number of rows. I have created a demonstration of this issue on the Vega online editor. You can view it here: Vega Editor

Any suggestions on how to rectify this or if there is an alternative workaround available would be greatly appreciated.

Thank you for your time and assistancevega.github.io

  • 1
    Check out this recent example using facet: https://stackoverflow.com/a/76170781/21427725 – APB Reports Jun 10 '23 at 06:53
  • 1
    Hi @Cristobal, for the facet itself, it seems like your question here might be related to this enhancement request on the Vega-Lite GitHub (https://github.com/vega/vega-lite/issues/8064) about adding resolve for "row"/"column" encodings. – sabine Jun 13 '23 at 20:41

1 Answers1

1

I came up with a potential workaround for this solution using a "window" transform (link) to compute a new field to use for the "row" facet. At the start of the specification, you can use a "window" transform grouped by the category to determine the row index for each subplot:

"transform": [
  {
    "window": [{"op": "row_number"}], 
    "groupby": ["VEDA Measure Category"]
  }
],

The modified data would look like the following, with the last column corresponding to the newly computed "row_number". Notice that when we switch from "Category 1" to "Category 2", the count from 1 starts over:

table showing modified data ... table showing modified data, cont.

Then, you can simply change your "facet" definition to use "row_number" instead of the measure name. Here is a link to the modified example in the Vega editor. Notice that I also set the "header" to null on line 15 to remove the overlapping labels.

sabine
  • 340
  • 1
  • 8
  • Thank you for your suggestion! Using the "window" transform to compute a new field for the row index seems like a promising approach to address the issue. I appreciate the detailed explanation and the modified example you provided in the Vega editor. I genuinely appreciate your assistance and the time you took to help me with this issue. Your suggestion has given me valuable insights, and I will further explore its applicability to my specific case. If I have any further questions or concerns, I will reach out for additional guidance. Thank you once again for your help! – Cristobal salcedo Jun 15 '23 at 16:06