箱线图无法适当显示
Boxplot cannot appropriate display
我已经按照 vega-Lite 网页给出的模板进行操作:
https://vega.github.io/vega-lite/docs/boxplot.html
我写的代码如下。但是,它无法显示箱线图。相反,它只是通过一条垂直线显示几个点。我正在考虑 Vega-Lite 是否不能自动将原始数据转换为箱线图。
我是否需要提前为我的数据计算最大值、最小值、1st/3rd Q?但如果是这样,我该如何填写代码并进行计算呢?
{
"$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"
标记 属性 到 zoom-in 来更好地查看:
{
"$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]}
}
}
}
但是,此视图遗漏了大量数据,因此简单的箱线图可能不适合此数据集的可视化。
我已经按照 vega-Lite 网页给出的模板进行操作: https://vega.github.io/vega-lite/docs/boxplot.html
我写的代码如下。但是,它无法显示箱线图。相反,它只是通过一条垂直线显示几个点。我正在考虑 Vega-Lite 是否不能自动将原始数据转换为箱线图。
我是否需要提前为我的数据计算最大值、最小值、1st/3rd Q?但如果是这样,我该如何填写代码并进行计算呢?
{
"$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"
标记 属性 到 zoom-in 来更好地查看:
{
"$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]}
}
}
}
但是,此视图遗漏了大量数据,因此简单的箱线图可能不适合此数据集的可视化。