Deneb/Vega-Lite has built-in “binning” ability and can create histograms from raw data to display distributions. Further, while Power BI only permits a single dataset to be provided to custom visuals, additional datasets can be created using Vega-Lite’s data generators. The example herein consists of a 20-bin histogram of IMDB movie ratings overlaying a parameterized normal distribution using data from a sequence generator.
This example illustrates a number of Deneb/Vega-Lite features, including:
0 - General:
- use of a “params” block to create range input widgets for the normal distribution height coefficient, mean, and standard deviation
- use of a “layer” block consisting of 2 sections: normal distribution, and histogram
1 - Normal Distribution:
- use a sequence generator to create a range dataset (0-10)
https://vega.github.io/vega-lite/docs/data.html#sequence - use of a “transform” block and the “densityNormal” statistical function to create a normal distribution using the range dataset
https://vega.github.io/vega/docs/expressions/
2 - Histogram:
- use of a “bar” mark with X encoding for binning (20) and Y encoding for aggregation (count)
{
"name": "HISTOGRAM",
"mark": {
"type": "bar",
"color": "#0F4C81",
"opacity": 0.7,
"tooltip": true
},
"encoding": {
"x": {
"bin": {"maxbins": 20},
"field": "IMDB Rating",
"type": "quantitative",
"title": "IMDB Rating",
"scale": {"domain": [0, 10]}
},
"y": {
"aggregate": "count",
"title": "Count"
}
}
}
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 sample PBIX using the movies JSON file provided on the Vega-Lite examples website.
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 - Distributions.pbix (1.5 MB)