在Vega-lite中分层汇总图表时夹紧y轴 [英] Clamping y-axis when layering aggregated charts in vega-lite

查看:123
本文介绍了在Vega-lite中分层汇总图表时夹紧y轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是来自


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 ?

解决方案

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:

这篇关于在Vega-lite中分层汇总图表时夹紧y轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆