Vega Lite Независимая шкала с несколькими слоями и фасетом - PullRequest
0 голосов
/ 15 декабря 2018

Можно ли иметь независимую шкалу для каждого фасета и каждого слоя?Разрешение прекрасно работает, когда у вас есть либо фасет, либо дополнительный слой, но я не могу заставить его сделать оба, задаваясь вопросом, возможно ли это вообще.

Что я хочу: Две шкалы на каждойсторона

, смешанная с гранением здесь

1 Ответ

0 голосов
/ 19 декабря 2018

То, как это выражается в 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 есть ошибка , которая делает невозможным его рендерингspec.

В качестве обходного пути вы можете вручную объединить две многоуровневые диаграммы с преобразованием фильтра, которое выбирает желаемое подмножество данных для каждой.Например:

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

enter image description here

...