Deneb Example - Scatterplot Matrix (SPLOM)

Deneb/Vega-Lite can use the repeat operator to easily create a scatterplot matrix, or SPLOM, which can be especially useful to visualize how various characteristics may relate to one another. The example herein consists of a 3x3 matrix of scatterplots showing displacement, fuel economy, and CO2 emissions of 2023 vehicles, and use an interactive legend to provide real-time filtering.

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

  • use of a “repeat” block with :
    • displacement, fuel economy, and CO2 emissions on the rows, and
    • CO2 emissions, fuel economy, and displacement on the columns
  • use of a “spec” block with:
    • a “params” block with a parameter binding the “points” to the legend
    • a “point” mark
      • the X-axis bound to the repeat columns
      • the Y-axis bound to the repeat rows
      • the country colours use the current Power BI theme as enabled by Deneb
      • conditional opacity (1/0, or on/off) if the country is selected in the legend
      • a custom tooltip showing country, make, model, displacement, fuel economy, and CO2 emissions

In addition, all title, axis, and legend font characteristics are set in the “config” section.

NOTE: This is actually one of the simplest Deneb visuals created by the author in a long while (the code is short - only 95 lines), and is an excellent demonstration of the inherent power and effectiveness of Deneb and Vega-Lite as a visualization environment.

Deneb/Vega-Lite JSON Code
{
  "title": {
    "anchor": "start",
    "align": "left",
    "text": "Power BI Scatterplot Matrix (SPLOM) with Interactive Legend using Deneb",
    "font": "Verdana",
    "fontSize": 20,
    "fontWeight": "bold",
    "fontStyle": "normal",
    "offset": 10
  },
  "repeat": {
    "row": [
      "Displacement (litres)",
      "Fuel Economy (miles/gallon)",
      "CO2 Emissions (grams/mile)"
    ],
    "column": [
      "CO2 Emissions (grams/mile)",
      "Fuel Economy (miles/gallon)",
      "Displacement (litres)"
    ]
  },
  "spec": {
    "data": {"name": "dataset"},
    "width": 200,
    "height": 200,
    "mark": {
      "type": "point",
      "tooltip": true
    },
    "params": [
      {
        "name": "_country",
        "select": {
          "type": "point",
          "fields": ["Country"]
        },
        "bind": "legend"
      }
    ],
    "encoding": {
      "x": {
        "field": {"repeat": "column"},
        "type": "quantitative"
      },
      "y": {
        "field": {"repeat": "row"},
        "type": "quantitative",
        "axis": {"minExtent": 30}
      },
      "color": {
        "field": "Country",
        "type": "nominal",
        "scale": {
          "scheme": "pbiColorNominal"
        }
      },
      "opacity": {
        "condition": {
          "param": "_country",
          "value": 1
        },
        "value": 0
      },
      "tooltip": [
        {
          "field": "Country",
          "type": "nominal"
        },
        {
          "field": "Make",
          "type": "nominal"
        },
        {
          "field": "Model",
          "type": "nominal"
        },
        {
          "field": "Displacement (litres)",
          "type": "quantitative",
          "format": ".2r"
        },
        {
          "field": "Fuel Economy (miles/gallon)",
          "type": "quantitative"
        },
        {
          "field": "CO2 Emissions (grams/mile)",
          "type": "quantitative"
        }
      ]
    }
  }
}

The intent of this example is not to provide a finished visual, but rather to serve as a starting point for further custom visual development.

Also included is the development sample PBIX using public data from the Fuel Economy Guide for Model Year 2023 New Vehicles, U.S. Environmental Protection Agency and U.S. Department of Energy (fueleconomy.gov). As this is just an exercise, and to illustrate the interactive legend functionality, the data was extended by the author arbitrarily assigning vehicle manufacturers to a single country (e.g., Volkswagen → Germany, Ford → United States, etc.).

This example is provided as-is for information purposes only, and its use is solely at the discretion of the end user; no responsibility is assumed by the author.

Greg
Deneb Examples - Scatterplot Matrix - V2.pbix (1.3 MB)

4 Likes

marking as solved

@Greg I love the interactive legend - thanks!
kind regards
Valeria