categorical-data - 轻推/抖动:用分类 X 轴和 3 组图例绘制点
问题描述
我有一个看起来像这样的 vegalite 情节。有 3 个操作系统(参见图例),我正在为每个版本绘制一个评分器。我想在 y 轴上为给定版本“微调”/抖动 3 个操作系统的 x 值,以便它们不在一条线上。在 R 的格中,这将是“抖动”。有没有办法修改 vegalite 规格来做到这一点?我正在使用 R 的 vegawidget 并自己创建规范。
非常感谢
解决方案
Jitter or offset encodings are not yet implemented in Vega-Lite; see https://github.com/vega/vega-lite/issues/4703 for the relevant feature request.
In the meantime, the best way to approximate what you want is to use a column encoding, along with an x encoding built from a randomly-generated jitter. The transform and encoding might look something like this:
"transform": [{"calculate": "random()", "as": "jitter"}],
"encoding": {
"size": {"value": 65},
"column": {"field": "cv", "type": "ordinal", "spacing": 0},
"x": {
"field": "jitter",
"type": "quantitative",
"axis": {"title": null, "labels": false},
"scale": {"domain": [-1, 2]}
},
"y": {"field": "c", "type": "quantitative"},
"color": {"field": "os", "type": "nominal"}
}
A simplified example using your data can be seen here:
From there you can customize grids, ticks, labels, and the rest to get it to look how you would like. It's imperfect, but it's the only way to currently get this kind of behavior within the Vega-Lite grammar.
推荐阅读
- jquery - jQuery:按下按钮添加类并删除所有其他类
- javascript - Javascript手风琴功能应该多次工作
- laravel - Laravel 8 应用程序在 Ubuntu Apache 生产服务器上尝试使用 RapidAPI 时获得 CONNECTION REFUSED FOR URI
- python - 获取使用 matplotlib 创建的填充元素的坐标
- php - 如何修改用户表
- jenkins - 其他 VLAN 中的 Jenkins 从站
- python - 多个数据帧的均值和标准差
- c# - 更改 DecodePixelWidth/Height 后获取 BitmapImage 的原始大小
- sql - SQL Server - 如何选择星期一 - 星期日作为 varchar
- api - 当聊天室中没有用户可用的空间时,服务器的适当响应状态代码是什么?