Clamping y-axis when layering aggregated charts in vega-lite

丶灬走出姿态 提交于 2020-02-25 06:32:10

问题


This is a follow up from a previous question for wich I built a test case in a (hopefully now public) notebook and noticed the following behavior:

At the end of the notebook, in the section bugs you will notice that y-axis of the max_precipitation of the layered chart using is clamped to 10.

I tried changing the domain but the bars do not go above 10.

Here the code example in vega-lite's editor reproduced below:

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

Please help me understand what I am doing wrong ?


回答1:


It appears that the precipitation column is being parsed as strings rather than as numbers. You can specify the parsing format for the column using :

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

The result is here:



来源:https://stackoverflow.com/questions/60153985/clamping-y-axis-when-layering-aggregated-charts-in-vega-lite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!