`resolve_scaled` followed by `facet` gives an inscrutable error `Unrecognized scale name: "child_layer_0_y"`
Bug Description
Goal: create a layered chart, facet it, and resolve axis independently.
If the resolve_scale is not at the right place, it will fail with an error that gives no clue what the problem is.
Note that I used vega-altair to generate the expression, but I think that both altair and vega-lite have a part of responsability in the issue.
First attempt:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
"columns": 6,
"data": {
"values": [
{"country": 0, "v1": 100, "v2": 4, "date": 0},
{"country": 0, "v1": 200, "v2": 7, "date": 1},
{"country": 0, "v1": 300, "v2": 9, "date": 2},
{"country": 1, "v1": 400, "v2": 6, "date": 0},
{"country": 1, "v1": 500, "v2": 7, "date": 1},
{"country": 1, "v1": 600, "v2": 5, "date": 2}
]
},
"facet": {
"field": "country",
"type": "nominal"
},
"spec": {
"layer": [
{
"encoding": {
"x": {
"field": "date",
"type": "temporal"
},
"y": {
"field": "v1",
"type": "quantitative"
}
},
"mark": {
"type": "line",
"stroke": "red",
}
},
{
"encoding": {
"x": {
"field": "date",
"type": "temporal"
},
"y": {
"field": "v2",
"type": "quantitative"
}
},
"mark": {
"type": "line"
}
}
],
"resolve": {
"scale": {
"y": "independent"
}
}
}
}
I get the error:
Unrecognized scale name: "child_layer_0_y"
Second attempt. The difference is that resolve is specified at the root and not in the layers.
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
"columns": 6,
"data": {
"values": [
{"country": 0, "v1": 100, "v2": 4, "date": 0},
{"country": 0, "v1": 200, "v2": 7, "date": 1},
{"country": 0, "v1": 300, "v2": 9, "date": 2},
{"country": 1, "v1": 400, "v2": 6, "date": 0},
{"country": 1, "v1": 500, "v2": 7, "date": 1},
{"country": 1, "v1": 600, "v2": 5, "date": 2}
]
},
"facet": {
"field": "country",
"type": "nominal"
},
"resolve": {
"scale": {
"y": "independent"
}
},
"spec": {
"layer": [
{
"encoding": {
"x": {
"field": "date",
"type": "temporal"
},
"y": {
"field": "v1",
"type": "quantitative"
}
},
"mark": {
"type": "line",
"stroke": "red",
}
},
{
"encoding": {
"x": {
"field": "date",
"type": "temporal"
},
"y": {
"field": "v2",
"type": "quantitative"
}
},
"mark": {
"type": "line"
}
}
],
}
}
This time, it did not return an error:
Expected behaviour
The first attempt should either work, or either indicate that resolve is not set in the right place.
What do you mean by it doesn't work in the second case? The y axis is independent. Or do you mean you want dual axis chart? Then that's the first spec which as you noticed has a bug and breaks. It's supposed to work.
What do you mean by it doesn't work in the second case? The y axis is independent. Or do you mean you want dual axis chart? Then that's the first spec which as you noticed has a bug and breaks. It's supposed to work.
I must have mixed the codes I used to reproduce the bug. You're right, the second version works fine.