带箱形图的 Vega-Lite 梯度图例

Vega-Lite gradient legend with box plots

我正在尝试按照 here 在 vega-lite 箱形图上设置梯度图例。即使将颜色编码设置为“定量”,图例仍然带有符号。

您可以将 bar chart vs. box plot 的行为与定量颜色编码进行比较。条形图上的图例是渐变的,而箱形图上是带符号的。

知道为什么吗?

不确定是什么原因导致条形图和箱形图出现这种不一致的行为。这可以正常工作,但作为获取渐变图例的替代方法,您可以使用 fill 配置而不是 color,因为它似乎为 quantitative 类型带来了预期的图例。

参考以下代码段的 editor

{
  "config": {
    "view": {"continuousWidth": 400, "continuousHeight": 300},
    "axis": {"labelAngle": 360, "labelFontSize": 16, "titleFontSize": 16},
    "legend": {}
  },
  "height": 350,
  "width": 300,
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "A vertical box plot showing median and lower and upper quartiles of the distribution of body mass of penguins.",
  "data": {"url": "data/cars.json"},
  "mark": {
    "type": "boxplot",
    "orient": "horizontal",
    "size": 15,
    "median": {"stroke": "white", "strokeWidth": 0.5}
  },
  "encoding": {
    "x": {"field": "Miles_per_Gallon", "type": "quantitative"},
    "fill": {"field": "Cylinders", "type": "quantitative", "bin": false},
    "y": {"field": "Cylinders", "type": "quantitative"}
  }
}