gpt4 book ai didi

Vega-Lite 分层图表 : how to get tick marks and tick labels to span the entire axis?

转载 作者:行者123 更新时间:2023-12-01 13:11:25 31 4
gpt4 key购买 nike

我正在制作一个分层图表,其中有条形图和规则线。我遇到的问题是,在 x 轴上,刻度线和刻度标签只出现在条形图下方,不会跨越整个轴,因此在规则线下方没有刻度线和标签位于。这是我所看到的示例 ( link to Vega editor ):

{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {"url": "data/movies.json"},
"transform": [
{"calculate": "2*datum.IMDB_Rating", "as": "UpperLimit"}
],
"layer": [
{
"mark": "bar",
"encoding": {
"x": {"bin": true, "field": "IMDB_Rating", "type": "quantitative"},
"y": {"aggregate": "count", "type": "quantitative"}
}
},
{
"mark": "rule",
"encoding": {
"x": {
"aggregate": "max",
"field": "UpperLimit",
"type": "quantitative"
},
"color": {"value": "red"},
"size": {"value": 5}
}
}
]
}

Image of issue

如何让刻度线和标签跨越整个轴?在此先感谢您的帮助!

最佳答案

当您在编码中使用 bin 变换时,Vega-Lite 会调整默认轴属性以匹配 binning。您可以通过编码的 scaleaxis 属性手动重新调整这些,但我认为更简单的方法是将 bin 转换移动到图表的 transform规范。这是一个示例 ( Vega Editor ):

{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {"url": "data/movies.json"},
"transform": [
{"calculate": "2*datum.IMDB_Rating", "as": "UpperLimit"},
{
"bin": true,
"field": "IMDB_Rating",
"as": ["IMDB_Rating_0", "IMDB_Rating_1"]
}
],
"layer": [
{
"mark": "bar",
"encoding": {
"x": {
"field": "IMDB_Rating_0",
"type": "quantitative",
"bin": "binned"
},
"x2": {"field": "IMDB_Rating_1"},
"y": {"aggregate": "count", "type": "quantitative"}
}
},
{
"mark": "rule",
"encoding": {
"x": {
"aggregate": "max",
"field": "UpperLimit",
"type": "quantitative"
},
"color": {"value": "red"},
"size": {"value": 5}
}
}
]
}

enter image description here

关于Vega-Lite 分层图表 : how to get tick marks and tick labels to span the entire axis?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59685475/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com