vega-lite - Vega-lite default bar width strange
问题描述
I'm seeing the following oddly styled chart. I understand I can explicitly change the padding
etc., but the default vega-lite layout is usually pretty good. I'm confused what I'm doing that's leading to this sub-normal behavior. Thanks! Here is the code in the vega-lite editor
I understand that I can also change x's type
to ordinal
to make the styling better, though I'm not sure I understand still why it is the difference I see. I need the type to be quantitative so I get the min/max brush bound, as opposed to the set.
Also I actually do not even know how to manually set the bar width after reading the documentation here https://vega.github.io/vega-lite/docs/scale.html. If anyone might have a working example that would be great.
Thanks.
解决方案
正如@marcprux 所提到的,有预装箱支持,因此您不必在此处重复装箱转换。但是,目前 prebinned 支持同时需要bin_start
和bin_end
。
现在您可以修改规范以派生一个新的 bin_end 字段并将其与 x2 一起使用。
{
"data": ...
"transform": [{
"calculate": "datum.ShareWomen_bin+0.1",
"as": "ShareWomen_bin_end"
}],
"mark": "bar",
"encoding": {
"x": {"bin": {"binned": true, "step": 0.1}, "field": "ShareWomen_bin", "type": "quantitative", "title": "ShareWomen_bin"},
"x2": {"field": "ShareWomen_bin_end"},
"y": {"field": "count", "type": "quantitative"}
}
}
喜欢这个规范。
我可以看到我们不应该要求派生 bin_end ,因此创建了一个问题来跟踪此功能请求:https ://github.com/vega/vega-lite/issues/6086 。
顺便说一句,定量比例仅影响条形位置。
要直接设置条形大小,可以在标记定义中使用 size 属性:
mark: {type: "bar", size: 5}
推荐阅读
- regex - Wget 返回未知格式的图像 (jpg@f=)
- c# - 为什么在 Cosmos Db 中查询分区键时 Linq 查询不返回记录?
- laravel - 需要为 VS Code 安装 Laravel-ide-helper
- java - 是否可以广播应用程序是否打开
- github - 在 Github 拆分差异查看器上关闭自动换行
- reactjs - React App 同时包含函数式和类组件
- javascript - JS从这个对象内的嵌套对象调用函数
- java - 如何为 java 类创建 HarnessTest 类?
- git - “git push”错误,位指定原点和分支工作
- javascript - 如何单独播放由 MediaRecorder 创建的 WEBM 文件