2

是否可以为每个方面和每个层设置独立的比例?当您有一个方面或一个额外的层时,解决方案非常有用,但我无法同时做到这两个,想知道它是否可能。

我想要的是: 每边的两个秤

这里的刻面混合

4

1 回答 1

1

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

{
  "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 渲染器中存在一个错误,导致它无法渲染这个规范。

作为一种解决方法,您可以使用过滤器转换手动连接两个分层图表,为每个分层图表选择所需的数据子集。例如:

{
  "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"
}

在此处输入图像描述

于 2018-12-18T23:03:48.320 回答