Open
Description
openedon Sep 24, 2019
When creating a histogram, any bins with zero entries are left out of the data stream. This leads to strange results if you attempt to visualize a histogram with a stepped area chart. For example:
{
"mark": {"type": "area", "interpolate": "step"},
"encoding": {
"x": {"type": "quantitative", "bin": true, "field": "x"},
"y": {"type": "quantitative", "aggregate": "count"}
},
"data": {
"values": [
{"x": 0},
{"x": 0},
{"x": 0},
{"x": 5},
{"x": 5},
{"x": 7},
{"x": 10},
{"x": 10}
]
}
}
Compare this to the bar chart, which is roughly what I would expect the area chart to look like:
{
"mark": "bar",
"encoding": {
"x": {"type": "quantitative", "bin": true, "field": "x"},
"y": {"type": "quantitative", "aggregate": "count"}
},
"data": {
"values": [
{"x": 0},
{"x": 0},
{"x": 0},
{"x": 5},
{"x": 5},
{"x": 7},
{"x": 10},
{"x": 10}
]
}
}
The reason this happens is that the aggregation ignores bins that contain no points, as can be seen in this version of the chart:
{
"mark": {"type": "line", "point": true},
"encoding": {
"x": {"type": "quantitative", "bin": true, "field": "x"},
"y": {"type": "quantitative", "aggregate": "count"}
},
"data": {
"values": [
{"x": 0},
{"x": 0},
{"x": 0},
{"x": 5},
{"x": 5},
{"x": 7},
{"x": 10},
{"x": 10}
]
}
}
Is there any way to specify that the binned aggregate should actually return zero in bins that contain zero points?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment