如何在 Vega-Lite 中创建分组或成对箱线图?

How can I create grouped or pair-wise box plots in Vega-Lite?

喜欢这个: https://www.r-graph-gallery.com/265-grouped-boxplot-with-ggplot2/

我尝试了刻面、颜色通道和构图, 但结果并不如我所愿。

我的用例是为了轻松比较分组的均值,所以我需要并排分组的箱线图

您可以结合使用列和 x 编码来实现这一点。这是 vega 数据集人口数据 (vega editor link) 的示例:

{
  "data": {"url": "data/population.json"},
  "mark": {
    "type": "boxplot",
    "extent": "min-max"
  },
  "encoding": {
    "column": {"field": "age","type": "ordinal"},
    "y": {
      "field": "people",
      "type": "quantitative",
      "axis": {"title": "population"}
    },
    "x": {
      "field": "sex",
      "type": "nominal"
    },
    "color": {
      "field": "sex",
      "type": "nominal"
    }
  }
}