Skip to content

Deneb - Multiple Scatter Plots

Creating Interactive Scatter Plots in Power BI Using Deneb and Vega-Lite JSON

Power BI is well-known for its powerful visualization capabilities, but when you need more flexibility and control, you might want to explore custom visuals. One such tool that offers a ton of customization options is Deneb, a visual that allows you to write Vega-Lite JSON code directly in Power BI.

In this guide, we'll walk you through how to create multiple interactive scatter plots using Deneb and Vega-Lite JSON within Power BI. This approach offers flexibility for more complex scenarios and customization than the out-of-the-box visuals.

What You’ll Need

  • Power BI Desktop
  • Deneb Custom Visual (available via AppSource)
  • Familiarity with Vega-Lite and basic JSON

Step 1: Install Deneb in Power BI

To begin, you'll need to install the Deneb custom visual:

  1. In Power BI Desktop, go to the Visualizations pane.
  2. Click on the three dots (…) to Import from AppSource.
  3. Search for Deneb and add it to your Power BI report.

Once installed, drag the Deneb visual onto your report canvas.

Step 2: Prepare Your Data

For this example, let's assume we have a dataset with fields like Sales, Profit, and Product Category. This dataset will be used to create scatter plots showing the relationship between Sales and Profit across different categories.

Make sure your data is clean and ready for visualization. Ideally, you'd have numerical fields for the X and Y axes and a categorical field to color the scatter plot points.

Step 3: Set Up Basic Vega-Lite Code in Deneb

Deneb lets you write Vega-Lite JSON code directly, so we'll start with the basics:

json
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": []
},
"mark": "point",
"encoding": {
"x": {"field": "Sales", "type": "quantitative"},
"y": {"field": "Profit", "type": "quantitative"},
"color": {"field": "Product Category", "type": "nominal"}
}
}

In the JSON above:

  • x and y represent the Sales and Profit fields.
  • The color encoding applies a different color to each Product Category.

Step 4: Bind Your Data

To link your Power BI data to the Vega-Lite JSON, follow these steps:

  1. In the Deneb visual, click on the Data fields pane.
  2. Drag and drop your data fields (e.g., Sales, Profit, Product Category) into the corresponding placeholders.
  3. Replace the "data": {"values": []} part in the JSON code with "data": {"name": "data"} to use Power BI data dynamically.

Your Vega-Lite code now looks like this:

json
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"name": "data"
},
"mark": "point",
"encoding": {
"x": {"field": "Sales", "type": "quantitative"},
"y": {"field": "Profit", "type": "quantitative"},
"color": {"field": "Product Category", "type": "nominal"}
}
}

Step 5: Create Multiple Scatter Plots

To create multiple scatter plots, we’ll use faceting in Vega-Lite. Faceting allows you to split the dataset into multiple subplots based on a field.

In this case, let's facet the data by Region:

json
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"name": "data"
},
"facet": {
"column": {"field": "Region", "type": "nominal"}
},
"spec": {
"mark": "point",
"encoding": {
"x": {"field": "Sales", "type": "quantitative"},
"y": {"field": "Profit", "type": "quantitative"},
"color": {"field": "Product Category", "type": "nominal"}
}
}
}

Here’s what’s happening:

  • We added a facet property, with column specifying that we want to split the data by the Region field, creating a column of scatter plots for each region.

Step 6: Add Interactivity

One of the key advantages of using Vega-Lite is the ability to add interactions to your visuals. For example, you can enable tooltips and make points clickable:

json
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"name": "data"
},
"facet": {
"column": {"field": "Region", "type": "nominal"}
},
"spec": {
"mark": "point",
"encoding": {
"x": {"field": "Sales", "type": "quantitative"},
"y": {"field": "Profit", "type": "quantitative"},
"color": {"field": "Product Category", "type": "nominal"},
"tooltip": [
{"field": "Sales", "type": "quantitative"},
{"field": "Profit", "type": "quantitative"},
{"field": "Product Category", "type": "nominal"}
]
},
"selection": {
"click": {
"type": "single",
"on": "click",
"encodings": ["color"]
}
}
}
}

Now, when users hover over the points, they’ll see a tooltip with the sales, profit, and product category data. They can also click to select points based on color, allowing for more interactivity.

Step 7: Fine-Tune Your Layout

To ensure that your scatter plots are well-organized, you can adjust the layout to fit your needs. For instance, you can specify how many columns or rows of plots you want to display at a time:

json
"facet": {
"column": {"field": "Region", "type": "nominal", "spacing": 15}
}

Here, the spacing property adds some padding between the individual scatter plots to ensure they don’t appear too cluttered.

Step 8: Save and Use in Reports

Once you’ve fine-tuned your Vega-Lite code, save your Power BI report. You can now publish it and share it with others. Users can interact with your scatter plots, explore relationships between variables, and dive deeper into the data.

Conclusion

Using Deneb with Vega-Lite JSON in Power BI gives you unparalleled control over your visualizations. By leveraging these tools, you can create multiple scatter plots that are interactive, informative, and customized to meet specific reporting needs. Whether you’re working with complex data sets or need advanced visual interactions, this method will enhance your Power BI capabilities.

Try it out in your next report and take your visualizations to the next level!