Forum Discussion

centroid's avatar
centroid
Icon for Helper I rankHelper I
3 years ago

Custom Report, displaying general quantiles in bar chart style instead of boxplot

Hi,

I would like to create a general quantile report in a bar chart style. I am not sure how to this. See my below example. I did not find any downloable custom charts for this. My underlying dataset is organized as follows. In my dataset there are N locations (classes if you want) and for each location (or class) a large number of observations which should be put into the respective quantiles. The reason why I want to avoid boxplot is that the resulting report should be included in a publication to the general public, i.e. to non-statisticians, for marketing purposes.  Custom quantiles should be used instead of quartiles as well. How can I do this most efficiently?

4 Replies

  • ppm1's avatar
    ppm1
    Icon for Solution Sage rankSolution Sage

    This can be done with the Deneb visual. I did a quick POC but much more could be done to pretty it up. You should be able to take the code below, put it in the visual and edit the field mapping (to switch it to your data).

    Declarative Visualization in Power BI | Deneb

     

     

    {
      "data": {"name": "dataset"},
      "transform": [
        {
          "aggregate": [
            {
              "op": "min",
              "field": "Total Sales",
              "as": "Min"
            },
            {
              "op": "max",
              "field": "Total Sales",
              "as": "Max"
            },
            {
              "op": "median",
              "field": "Total Sales",
              "as": "Median"
            },
            {
              "op": "q1",
              "field": "Total Sales",
              "as": "Q1"
            },
            {
              "op": "q3",
              "field": "Total Sales",
              "as": "Q3"
            }
          ],
          "groupby": ["Subcategory"]
        }
      ],
      "layer": [
        {
          "mark": {
            "type": "bar",
            "color": "red"
          },
          "encoding": {
            "y": {
              "field": "Min",
              "type": "quantitative"
            },
            "y2": {"field": "Q1"}
          }
        },
        {
          "mark": {
            "type": "bar",
            "color": "blue"
          },
          "encoding": {
            "y": {
              "field": "Q1",
              "type": "quantitative"
            },
            "y2": {"field": "Median"}
          }
        },
        {
          "mark": {
            "type": "bar",
            "color": "green"
          },
          "encoding": {
            "y": {
              "field": "Median",
              "type": "quantitative"
            },
            "y2": {"field": "Q3"}
          }
        },
        {
          "mark": {
            "type": "bar",
            "color": "yellow"
          },
          "encoding": {
            "y": {
              "field": "Q3",
              "type": "quantitative"
            },
            "y2": {"field": "Max"}
          }
        }
      ],
      "encoding": {
        "x": {"field": "Subcategory"}
      }
    }

    Pat

     

    • centroid's avatar
      centroid
      Icon for Helper I rankHelper I

      That looks good, but instead of the minimum value, the 25 % quantile, the median and the 75 % quantile and the maximum value, I should have the quantile boundaries 5 %, 25 %, 75 % and 95 %. How do I do this?

      • ppm1's avatar
        ppm1
        Icon for Solution Sage rankSolution Sage

        This page shows the available aggregations in Vega Lite (Deneb). If the ci0 and ci1 work for your 5 and 95%, you can easily adapt the earlier code with those instead. Otherwise, you would a DAX approach to get the 5 and 95 percentile.

         

        Aggregation | Vega-Lite

         

        Pat