vega-lite
vega-lite copied to clipboard
Cannot sort faceted boxplots when extent is "min-max"
Boxplots can be nicely sorted by some aggregation function with faceting:
{
"$schema": "https://vega.github.io/schema/vega-lite/v3.json",
"config": {
"view": {"stroke": ""},
"header": {"labelAngle": 0},
"facet": {"spacing": 0}
},
"data": {
"values": [
{"x": 3, "y": "b"},
{"x": 4, "y": "b"},
{"x": 5, "y": "b"},
{"x": 1, "y": "a"},
{"x": 2, "y": "a"},
{"x": 3, "y": "a"},
{"x": 2, "y": "c"},
{"x": 3, "y": "c"},
{"x": 4, "y": "c"}
]
},
"encoding": {
"row": {
"field": "y",
"type": "nominal",
"sort": {"field": "x", "op": "median"}
},
"x": {"field": "x", "type": "quantitative"},
"color": {"field": "y", "type": "nominal"}
},
"mark": {"type": "boxplot", "extent": 1}
}
But if extent
is set to "min-max"
, sorting no longer works and boxplots are displayed in original row order (and not even in the field's natural order). Perhaps this bug is related to the cause of #4140?
{
"$schema": "https://vega.github.io/schema/vega-lite/v3.json",
"data": {
"values": [
{"x": 3, "y": "b"},
{"x": 4, "y": "b"},
{"x": 1, "y": "a"},
{"x": 2, "y": "a"},
{"x": 2, "y": "c"},
{"x": 3, "y": "c"}
]
},
"facet": {
"row": {
"field": "y",
"type": "nominal",
"sort": {"field": "x", "op": "median"}
}
},
"spec": {
"transform": [
{
"aggregate": [{"op": "mean", "field": "x", "as": "mean_x"}],
"groupby": []
}
],
"mark": "point",
"encoding": {"x": {"field": "mean_x", "type": "quantitative"}}
}
}
also produces this output:
Without the transform, the output is produced correctly.
It appears that the issue isn't due to the min-max extent. I'm getting the same issue if I set outliers and rule to false, rather than setting the extent. (If I only set either one of the two, it sorts correctly)
{
"$schema": "https://vega.github.io/schema/vega-lite/v3.json",
"config": {
"view": {"stroke": ""},
"header": {"labelAngle": 0},
"facet": {"spacing": 0}
},
"data": {
"values": [
{"x": 3, "y": "b"},
{"x": 4, "y": "b"},
{"x": 5, "y": "b"},
{"x": 1, "y": "a"},
{"x": 2, "y": "a"},
{"x": 3, "y": "a"},
{"x": 2, "y": "c"},
{"x": 3, "y": "c"},
{"x": 4, "y": "c"}
]
},
"encoding": {
"row": {
"field": "y",
"type": "nominal",
"sort": {"field": "x", "op": "median"}
},
"x": {"field": "x", "type": "quantitative"},
"color": {"field": "y", "type": "nominal"}
},
"mark": {"type": "boxplot", "outliers": false, "rule": false}
}