【问题标题】:Vega-Lite - How to plot stacked bar with labels in each nar?Vega-Lite - 如何在每个 nar 中绘制带有标签的堆叠条?
【发布时间】:2020-12-18 16:31:36
【问题描述】:

给定一个堆积条形图,我如何添加带有每个条形值的标签?

以下是我正在尝试做的一个示例:

【问题讨论】:

    标签: plot text label data-visualization vega-lite


    【解决方案1】:

    您可以通过将条形标记和文本标记分层来做到这一点。例如(open in editor):

    {
      "data": {"url": "data/barley.json"},
      "width": 400,
      "encoding": {
        "x": {
          "type": "quantitative",
          "aggregate": "sum",
          "field": "yield",
          "stack": "zero"
        },
        "y": {"type": "nominal", "field": "variety"}
      },
      "layer": [
        {
          "mark": "bar",
          "encoding": {"color": {"type": "nominal", "field": "site"}}
        },
        {
          "mark": {"type": "text", "color": "white", "dx": -15, "dy": 3},
          "encoding": {
            "detail": {"type": "nominal", "field": "site"},
            "text": {
              "type": "quantitative",
              "aggregate": "sum",
              "field": "yield",
              "format": ".1f"
            }
          }
        }
      ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-20
      相关资源
      最近更新 更多