您可以在单个Vegalite图中具有多个面和图层吗?

时间:2020-10-18 22:22:14

标签: vega-lite vega

我正在努力理解为什么这样的图层规格如下:

"layer": [
    {"encoding": {
        "facet": {"field": "FEATURE_VALUE"},
        "x": {
            "field": "DATE",
            "type": "temporal"
        },
        "y": {
            "field": "VALUE",
            "type": "quantitative"
        }
    },
    "mark": {
        "type": "line"
    }}
    ]

引发错误,导致:Cannot read property 'push' of undefined

同时,单位规格:

"encoding": {
        "facet": {"field": "FEATURE_VALUE"},
        "x": {
            "field": "DATE",
            "type": "temporal"
        },
        "y": {
            "field": "VALUE",
            "type": "quantitative"
        }
    },
    "mark": {
        "type": "line"
    }
}

工作正常。

我可以说这与以下情况有关:Altair: Can't facet layered plots

但是,似乎还不能完全回答这个基本问题:我可以使用facet来制作网格图吗,还可以在其上放置图层(例如工具提示,标尺等)

谢谢!

1 个答案:

答案 0 :(得分:1)

Vega-Lite提供了两种方法来指定构面:作为编码(请参见Facet, Row, and Column Encoding Channels)和作为运算符(请参见Facet Operator)。

不允许图层图包含构面编码,但是构面运算符可以包含图层表(原因是不清楚包含不兼容构面的图层的语义)。

所以,不要像这样:

"layer": [
    {"encoding": {
        "facet": {"field": "FEATURE_VALUE"},
        "x": {
            "field": "DATE",
            "type": "temporal"
        },
        "y": {
            "field": "VALUE",
            "type": "quantitative"
        }
    },
    "mark": {
        "type": "line"
    }}
]

您可以执行以下操作:

"facet": {"field": "FEATURE_VALUE"},
"spec": {
  "layer": [
    {"encoding": {
        "x": {
            "field": "DATE",
            "type": "temporal"
        },
        "y": {
            "field": "VALUE",
            "type": "quantitative"
        }
    },
    "mark": {
        "type": "line"
    }}
  ]
}