1

Here is a post showing how to plot histogram in Google Looker Studio. The solution of the post works well when that data is almost "continuous", but some bins will not be shown when there is a big gap between data. For example, if my raw data is [1,2,3,4,5,6,7,8,9,1000], the bins between 10-999 will not be shown. How can I show those bins with zero y-value in Google Looker Studio?

My data source is a CSV file. A general solution is better.

IvanaGyro
  • 598
  • 7
  • 25

1 Answers1

1

There is no way to force zero bar entries with the standard graphs in Looker Studio. A solution can be the use of customer viz, such as the VEGA plugin.

Please use then following Vega code:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
 "mark": {"type": "bar", "tooltip": true},
  "encoding": {
    "x": {
      "bin": {"binned": true, "step": 1},
      "field": "$dimension0"
    },
    "y": {"aggregate": "sum",
         "field":"$metric0"
         }
  }
}

The step under bin sets the width of a bar.

enter image description here

For building non linear range, there is the need to create an extra column:

CASE 
WHEN Age <=  5 THEN FLOOR(age/1) * 1
WHEN Age <= 20 THEN FLOOR(age/5) * 5
WHEN Age <= 100 THEN FLOOR(age/10) * 10
WHEN Age <= 1000 THEN FLOOR(age/100) * 100
ELSE -1
END
Samuel
  • 2,923
  • 1
  • 4
  • 19
  • I need the scale of the x-axis to be linear. Take `[1,2,3,4,5,6,7,8,9,1000]` for example, I need 1000 bins. Is it possible? – IvanaGyro Jan 19 '23 at 16:37