Boxplot无法正确显示

问题描述

我遵循了vega-Lite网页上给出的模板: https://vega.github.io/vega-lite/docs/boxplot.html

我写如下代码。但是,它无法显示箱线图。取而代之的是,它仅通过一条垂直线显示了几个点。我正在考虑Vega-Lite是否无法将原始数据自动转换为箱线图。

我是否必须预先计算数据的最大,最小,第一/第三问?但是如果是这样,我该如何填写代码并进行计算?

enter image description here

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json","description": "A vertical Box plot showing median and lower and upper quartiles of the distribution.","data": {"url": "https://raw.githubusercontent.com/BocongZhao823/My_First_Webpage-/main/data/rainfall_tidy.csv"},"mark": "Boxplot","encoding": {
    "x": {"field": "city_name","type": "nominal"},"color": {"field": "city_name","type": "nominal","legend": null},"y": {
      "field": "rainfall","type": "quantitative","scale": {"zero": false}
    }
  }
}

解决方法

箱线图正在工作,您的数据仅是难以置信的歪斜–四分位数范围在0到0.8之间,但最大值在350左右,因此箱图的框部分太小了,看不到。

通过将y域设置为较小的范围,并使用"clip"标记属性放大感兴趣的区域,您可以更好地看到这一点:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json","description": "A vertical box plot showing median and lower and upper quartiles of the distribution.","data": {"url": "https://raw.githubusercontent.com/BocongZhao823/My_First_Webpage-/main/data/rainfall_tidy.csv"
  },"mark": {"type": "boxplot","clip": true},"encoding": { 
    "x": {"field": "city_name","type": "nominal"},"color": {"field": "city_name","type": "nominal","legend": null},"y": {
      "field": "rainfall","type": "quantitative","scale": {"domain": [0,3]}
    }
  }
}

enter image description here

但是,此视图遗漏了大量数据,因此简单的箱形图可能不适用于此数据集。