Vega-lite 项目:风险矩阵

Vega-lite project: Risk matrix

我在 Vega 方面是个新手,希望得到任何帮助。我目前正在创建一个风险矩阵,其中包含“潜在损害”和“风险暴露”两个维度。最终目标是在 PowerBI 中使用。

我的当前状态可以在这里看到:https://vega.github.io/editor/#/gist/d534904674d14f005e7cb08811dc8b62/spec.json

现在我面临两个主要挑战:

欢迎任何帮助。 :)

给你。

Editor.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "url": "https://gist.githubusercontent.com/Hatico90/ec1d58ef5fe5d91cf6438e66fcd40bf0/raw/c5737c70fd45807a8435f2a97fe17fbc03bddf2b/riskmatrix",
    "format": {"type": "json"}
  },
  "width": 500,
  "height": 500,
  "transform": [
    {
      "pivot": "Exposure",
      "groupby": ["Damage"],
      "value": "Index",
      "op": "count"
    },
    {"fold": ["high", "low", "medium"]}
  ],
  "encoding": {
    "y": {
      "field": "key",
      "type": "ordinal",
      "scale": {"domain": ["high", "medium", "low"]}
    },
    "x": {
      "field": "Damage",
      "type": "ordinal",
      "scale": {"domain": ["low", "medium", "high"]}
    }
  },
  "layer": [
    {
      "mark": "rect",
      "data": {
        "values": [
          {"x": "low", "y": "low", "t": "green"},
          {"x": "low", "y": "medium", "t": "green"},
          {"x": "low", "y": "high", "t": "yellow"},
          {"x": "medium", "y": "low", "t": "green"},
          {"x": "medium", "y": "medium", "t": "yellow"},
          {"x": "medium", "y": "high", "t": "red"},
          {"x": "high", "y": "low", "t": "yellow"},
          {"x": "high", "y": "medium", "t": "red"},
          {"x": "high", "y": "high", "t": "red"}
        ]
      },
      "encoding": {
        "color": {
          "type": "nominal",
          "field": "t",
          "scale": {"range": {"field": "t"}},
          "legend": null
        },
        "y": {
          "field": "y",
          "type": "ordinal",
          "scale": {"domain": ["high", "medium", "low"]}
        },
        "x": {
          "field": "x",
          "type": "ordinal",
          "scale": {"domain": ["low", "medium", "high"]}
        }
      }
    },
    {
      "mark": {"type": "text"},
      "encoding": {"text": {"field": "value", "type": "quantitative"}}
    }
  ],
  "config": {"axis": {"grid": true, "tickBand": "extent"}}
}