Зажим оси Y при наложении агрегированных диаграмм в vega-lite - PullRequest
1 голос
/ 10 февраля 2020

Это продолжение предыдущего вопроса , для которого я построил тестовый пример в (надеюсь, теперь опубликованном c) блокноте и заметил следующее поведение:

В конце блокнота в разделе ошибки вы заметите, что y-axis из max_precipitation многоуровневой диаграммы с использованием ограничено до 10.

I попытался изменить домен, но баров не go выше 10.

Вот пример кода в редакторе vega-lite , приведенный ниже:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "title": "Top Months by Mean Precipitation",
  "data": {"url": "data/seattle-weather.csv"},
  "transform": [
    {"timeUnit": "month", "field": "date", "as": "month_date"},
    {
      "aggregate": [
        {"op": "mean", "field": "precipitation", "as": "mean_precipitation"},
        {"op": "max", "field": "precipitation", "as": "max_precipitation"}
      ],
      "groupby": ["month_date"]
    },
    {
      "window": [{"op": "row_number", "as": "rank"}],
      "sort": [{"field": "mean_precipitation", "order": "descending"}]
    }
  ],
  "encoding": {
    "x": {
      "field": "month_date",
      "type": "ordinal",
      "timeUnit": "month",
      "title": "month (descending by max precip)",
      "sort": {
        "field": "max_precipitation",
        "op": "average",
        "order": "descending"
      }
    }
  },
  "layer": [
    {
      "mark": {"type": "bar"},
      "encoding": {
        "y": {
          "field": "max_precipitation",
          "type": "quantitative",
          "title": "precipitation (mean & max)"
        }
      }
    },
    {
      "mark": "tick",
      "encoding": {
        "y": {"field": "mean_precipitation", "type": "quantitative"},
        "color": {"value": "red"},
        "size": {"value": 15}
      }
    }
  ]
}

Пожалуйста, помогите мне понять, что я делаю не так?

1 Ответ

1 голос
/ 10 февраля 2020

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

"data": {
  "url": "data/seattle-weather.csv",
  "format": {"parse": {"precipitation": "number"}}
},

Результат здесь :

enter image description here

...