如果我在这里将horizontal
更改为vertical
,则轴不会切换:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"layer": [{
"data": {"values": [
{"x": 0.5, "y": 0},
{"x": 1, "y": 1},
{"x": 2, "y": 2}]},
"mark": {"type": "line", "orient": "horizontal"},
"encoding": {
"x": {"field": "x", "type": "quantitative"},
"y": {"field": "y", "type": "quantitative"},
"color": {"datum": "a"}}
}, {
"data": {"values": [
{"x": 1, "y": 0},
{"x": 2, "y": 1},
{"x": 2.5, "y": 2}]},
"mark": {"type": "line", "orient": "horizontal"},
"encoding": {
"x": {"field": "x", "type": "quantitative"},
"y": {"field": "y", "type": "quantitative"},
"color": {"datum": "b"}}
}
]
}
为什么?如何让x轴和y轴互换位置?
还需要切换"x"one_answers";y"encoding"属性:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"layer": [{
"data": {"values": [
{"x": 0.5, "y": 0},
{"x": 1, "y": 1},
{"x": 2, "y": 2}]},
"mark": {"type": "line", "orient": "vertical"},
"encoding": {
"x": {"field": "y", "type": "quantitative"},
"y": {"field": "x", "type": "quantitative"},
"color": {"datum": "a"}}
}, {
"data": {"values": [
{"x": 1, "y": 0},
{"x": 2, "y": 1},
{"x": 2.5, "y": 2}]},
"mark": {"type": "line", "orient": "vertical"},
"encoding": {
"x": {"field": "y", "type": "quantitative"},
"y": {"field": "x", "type": "quantitative"},
"color": {"datum": "b"}}
}
]
}