Deneb Example - Heat Lane Chart

Deneb/Vega-Lite can be used to create a Heat Lane Chart, an alternative to a histogram or heatmap that uses an accessibility-first design approach to present the distribution of a variable. The example presented herein addresses two common accessibility concerns:

  • colour blindness: use something beyond colour to communicate meaning and reduce the dependency of interpreting colours
    • in this example, bar height and no y-axis
  • colour contrast: use binning and a discrete sequential colour palette (or a “colour ramp”) to minimize the colour range
    • in this example, fill colour opacity and end caps

This example illustrates a number of Deneb/Vega-Lite features, including:
0 - General:

  • a “title” block with subtitle
  • a “transform” block to aggregate and extend the dataset in-visual with:
    • a “bin” transform to categorize the continuous source vehicle fuel economy dataset
    • an “aggregate/count” transform to reduce and group the dataset into up-to 20 categorical “bins”
    • a “bin” transform to categorize the aggregated vehicle counts
    • a “calculate” transform to determine the Y coordinate of the upper column end (bin end count / 2)
    • a “calculate” transform to determine the Y coordinate of the lower column end (-1 * bin end count / 2)
    • a “joinaggregate/max” transform to determine the maximum of the bin end count
  • a shared “encoding” block (for the following layer block) for the ranged X and Y axes (Y-axis is hidden so the relative column heights provide the insights)
  • a “layer” block for the end caps and columns

1 - Binned End Caps:

  • a full-height “bar” mark for the “background” column using the maximum binned vehicle count centered at Y=0 and a ramped colour scale from the Min divergent colour to the Max divergent colour from the current Power BI theme as enabled by Deneb
    • use of the maximum binned vehicle count ensures the Max divergent colour (the darkest) is used

2 - Binned Columns:

  • a partial-height (full height - 10 px) “bar” mark for the “foreground” column using the binned vehicle counts centered at Y=0
    • uses the same ramped colour scale from the Min divergent colour to the Max divergent colour from the current Power BI theme as enabled by Deneb
    • overlays the background column except for a 5 px range at each end, exposing and thus creating the “caps”

Deneb/Vega-Lite JSON Specification Code:

{
  "title": {
    "anchor": "start",
    "align": "left",
    "offset": 10,
    "text": "Power BI Heat Lane Chart using Deneb",
    "font": "Verdana",
    "fontSize": 32,
    "fontWeight": "bold",
    "fontStyle": "normal",
    "subtitle": "Data source: US Environmental Protection Agency/Fuel Economy (https://www.fueleconomy.gov/feg/download.shtml (2024 Datafile); 2024 FE Guide ...xlsx (819 rows)",
    "subtitleFont": "Verdana",
    "subtitleFontSize": 12,
    "subtitleFontWeight": "normal",
    "subtitleFontStyle": "italic"
  },
  "data": {"name": "dataset"},
  "height": 680,
  "width": 1260,
  "transform": [
    {
      "bin": {"maxbins": 20},
      "field": "Fuel Economy - Combined",
      "as": [
        "_bin_fuel_economy_start",
        "_bin_fuel_economy_end"
      ]
    },
    {
      "aggregate": [
        {
          "op": "count",
          "field": "Index",
          "as": "_count"
        }
      ],
      "groupby": [
        "_bin_fuel_economy_start",
        "_bin_fuel_economy_end"
      ]
    },
    {
      "bin": true,
      "field": "_count",
      "as": [
        "_bin_count_start",
        "_bin_count_end"
      ]
    },
    {
      "calculate": "datum['_bin_count_end'] / 2",
      "as": "_y"
    },
    {
      "calculate": "-1 * datum['_y'] ",
      "as": "_y2"
    },
    {
      "joinaggregate": [
        {
          "op": "max",
          "field": "_bin_count_end",
          "as": "_max_bin_count_end"
        }
      ]
    }
  ],
  "encoding": {
    "x": {
      "field": "_bin_fuel_economy_start",
      "type": "quantitative",
      "axis": {
        "labelFont": "Segoe UI",
        "labelFontSize": 12,
        "title": "Fuel Economy - Combined (mpg)",
        "titleFont": "Segoe UI",
        "titleFontSize": 16
      }
    },
    "x2": {
      "field": "_bin_fuel_economy_end"
    },
    "y": {"field": "_y", "axis": null},
    "y2": {"field": "_y2"}
  },
  "layer": [
    {
      "name": "COLUMN_END_CAPS",
      "mark": {
        "type": "bar",
        "xOffset": 2,
        "x2Offset": -2
      },
      "encoding": {
        "color": {
          "field": "_max_bin_count_end",
          "type": "ordinal",
          "scale": {
            "scheme": "pbiColorOrdinal"
          },
          "legend": {
            "title": "Vehicle Count"
          }
        }
      }
    },
    {
      "name": "COLUMNS",
      "mark": {
        "type": "bar",
        "xOffset": 2,
        "x2Offset": -2,
        "yOffset": -5,
        "y2Offset": 5
      },
      "encoding": {
        "color": {
          "field": "_bin_count_end",
          "type": "ordinal"
        }
      }
    }
  ]
}

One claim of such an accessibility-first design approach is that it increases the clarity of insights and thus improves comprehension for all users. An analysis of the merits of this claim is beyond the scope of this example, but rather, it served as an interesting (for me, at least) test case for the use of the Deneb custom visual within Power BI.

This example used the heat lane chart example on the Vega-Lite website https://vega.github.io/vega-lite/examples/bar_heatlane.html as a starting point which, in turn, references the document, “An Accessibility-First Approach To Chart Visual Design” https://www.smashingmagazine.com/2022/07/accessibility-first-approach-chart-visual-design/.

For more information on accessible design, one resource is the Web Content Accessibility Guidelines (WCAG) at https://www.w3.org/TR/WCAG21/.

Greg
Deneb Examples - Heat Lane Chart.pbix (1.4 MB)

1 Like

marking as solved