在具有灰色背景的 vega-lite 中绘制小​​倍数

plot small multiples in vega-lite with gray background

我正在寻找一个 vega-lite 配置来显示小的倍数(使用 facet 运算符行或列),所有其他数据点在背景中显示为灰色。

这是一个使用 facet-operator 的示例图: facet plot

in vega-editor

"facet": {
        "row": {
          "field": "group",
          "type": "nominal"
        }
      },

下面是一个使用多个图表和连接运算符和颜色通道来使其他组变灰的示例: concat-plot

in vega-editor

"color": {"condition": {"test": "datum['group'] != 1", "value": "grey"}, "value": "red"}

我想知道是否有转换和重复命令的组合来为未知数量的组实现此目的。

这是一种可能的解决方案:

使用新数据创建一个附加层

"facet": {"row": {"field": "group"}},
      "spec": {
        "layer": [
          {
            "data": {"name": "main"},
            "mark": "circle",
            "encoding": {
              "y": {
                "field": "y",
                "type": "ordinal"
              },
              "x": {
                "field": "x",
                "type": "ordinal"
              },
              "color": {"value": "grey"}
            },
            "params": []
          },
          {
            "mark": {"type": "circle", "opacity": 1, "color": "red"},
            "encoding": {
              "y": {
                "field": "y",
                "type": "ordinal"
              },
              "x": {
                "field": "x",
                "type": "ordinal"
              }
            }
          }
        ]
      }

full example in vega editor