Vega-Lite:是否可以将图像作为折线图中的标签?

Vega-Lite: Is it possible to have images as labels in a line chart?

我想要图像作为我的轴标签。我尝试使用图像标记,但没有用,这是意料之中的。标签表达式也是我尝试过的,但是如果我想让它成为图像,那是行不通的。我还能尝试什么或完全有可能吗?

Line chart example

使用 中相同的技术,可以通过额外的层添加图像轴:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      {"x": 0.5, "y": 0.5, "img": "data/ffox.png"},
      {"x": 1.5, "y": 1.5, "img": "data/gimp.png"},
      {"x": 2.5, "y": 2.5, "img": "data/7zip.png"}
    ]
  },
  "layer": [{
    "mark": {"type": "image", "width": 50, "height": 50},
    "encoding": {
      "x": {"field": "x", "type": "quantitative"},
      "y": {"field": "y", "type": "quantitative"},
      "url": {"field": "img", "type": "nominal"}
    }
  }, {
    "transform": [{"calculate": "-.2", "as": "axis"}],
    "mark": {"type": "image", "width": 25, "height": 25},
    "encoding": {
      "x": {"field": "x", "type": "quantitative", "axis":{"labelExpr": "", "title": null}},
      "y": {"field": "axis", "type": "quantitative", "scale": {"domain": [0, 2.5]}},
      "url": {"field": "img", "type": "nominal"}
    }
  }],
  "resolve": {"scale": {"y": "shared"}}
}

Vega Editor

===== 2021-07-20 =====

您的条形图的 x 编码使用了 x 字段,该字段分布不均,因此未对齐。

如果您的编辑器中确实显示了 a 字段,最简单的方法是将编码替换为 "x": {"field": "a", "type": "ordinal", "axis": null}

Vega Editor

即使 a 字段不存在,您可能想添加这样一个字段来对齐甚至排序图像轴。

我能想到的最后一招是 window 变换,这是一种矫枉过正,但也没有增加额外的价值:

Vega Editor