Vega Lite 独立刻度,具有多层和刻面

Vega Lite Independent Scale with Multiple Layers and Facet

能不能每个切面、每一层都有一个独立的尺度?当你有一个面或一个额外的层时,这个解决方案很有效,但我不能让它同时做这两个,想知道它是否可能。

我想要的是: The two scales on each side

混合 the faceting here

这在 Vega-Lite 中的表达方式是在一个面内使用一个带有解析集的层。像这样:

{
  "data": {
    "url": "https://vega.github.io/vega-datasets/data/seattle-weather.csv"
  },
  "facet": {
    "column": {
      "field": "weather",
      "type": "nominal"
    }
  },
  "spec": {
    "layer": [
      {
        "encoding": {
          "x": {
            "field": "date",
            "timeUnit": "month",
            "type": "temporal"
          },
          "y": {
            "aggregate": "mean",
            "field": "temp_max",
            "type": "quantitative"
          }
        },
        "mark": {
          "color": "salmon",
          "type": "line"
        }
      },
      {
        "encoding": {
          "x": {
            "field": "date",
            "timeUnit": "month",
            "type": "temporal"
          },
          "y": {
            "aggregate": "mean",
            "field": "precipitation",
            "type": "quantitative"
          }
        },
        "mark": {
          "color": "steelblue",
          "type": "line"
        }
      }
    ],
    "resolve": {
      "scale": {
        "y": "independent"
      }
    }
  }
}

虽然此规范根据 Vega-Lite 架构有效,但不幸的是,在 vega-lite 渲染器中存在 bug 使其无法渲染此规范。

作为一种变通方法,您可以手动将两个分层图表与过滤转换连接起来,为每个图表选择所需的数据子集。例如:

{
  "data": {
    "url": "https://vega.github.io/vega-datasets/data/seattle-weather.csv"
  },
  "hconcat": [
    {
      "layer": [
        {
          "mark": {"type": "line", "color": "salmon"},
          "encoding": {
            "x": {"type": "temporal", "field": "date", "timeUnit": "month"},
            "y": {
              "type": "quantitative",
              "aggregate": "mean",
              "field": "temp_max"
            }
          }
        },
        {
          "mark": {"type": "line", "color": "steelblue"},
          "encoding": {
            "x": {"type": "temporal", "field": "date", "timeUnit": "month"},
            "y": {
              "type": "quantitative",
              "aggregate": "mean",
              "field": "precipitation"
            }
          }
        }
      ],
      "resolve": {"scale": {"y": "independent", "x": "shared"}},
      "transform": [{"filter": "(datum.weather === 'sun')"}]
    },
    {
      "layer": [
        {
          "mark": {"type": "line", "color": "salmon"},
          "encoding": {
            "x": {"type": "temporal", "field": "date", "timeUnit": "month"},
            "y": {
              "type": "quantitative",
              "aggregate": "mean",
              "field": "temp_max"
            }
          }
        },
        {
          "mark": {"type": "line", "color": "steelblue"},
          "encoding": {
            "x": {"type": "temporal", "field": "date", "timeUnit": "month"},
            "y": {
              "type": "quantitative",
              "aggregate": "mean",
              "field": "precipitation"
            }
          }
        }
      ],
      "resolve": {"scale": {"y": "independent", "x": "shared"}},
      "transform": [{"filter": "(datum.weather === 'fog')"}]
    }
  ],
  "$schema": "https://vega.github.io/schema/vega-lite/v2.6.0.json"
}