【问题标题】:How align axes when creating a plot matrix in vega using vconcat and hconcat?使用 vconcat 和 hconcat 在 vega 中创建绘图矩阵时如何对齐轴?
【发布时间】:2022-01-24 20:46:00
【问题描述】:

考虑绘图矩阵(例如 3 x 3 散点图网格),其中所有维度共享轴,但不同轴的比例不同(例如,考虑日期、对数数量、线性)。

为此,您可以通过图表规范的 vconcat 和 hconcat 创建一个矩阵。

从文档看来,您应该使用 minExtent 和 maxExtent 来对齐轴,但是我不清楚 在哪里 应用此配置?它需要处于最低图表规范级别,因为轴范围都不同,具体取决于所考虑矩阵的角色和列。

查看图片以获取未对齐示例

【问题讨论】:

    标签: vega-lite vega


    【解决方案1】:

    根据docs,您需要在axis配置中提供minExtentmaxExtent

    以下是示例配置或参考editor

    {
      "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
      "description": "Two horizonally concatenated charts that show a histogram of precipitation in Seattle and the relationship between min and max temperature.",
      "data": {"url": "data/weather.csv"},
      "transform": [{"filter": "datum.location === 'Seattle'"}],
      "columns": 3,
      "config": {"axisY": {"minExtent": 50, "maxExtent": 100}},
      "concat": [
        {
          "mark": "bar",
          "encoding": {
            "x": {"timeUnit": "month", "field": "date", "type": "ordinal"},
            "y": {
              "aggregate": "mean",
              "field": "precipitation",
              "axis": {"format": ".4f"}
            }
          }
        },
        {
          "mark": "bar",
          "encoding": {
            "x": {"timeUnit": "month", "field": "date", "type": "ordinal"},
            "y": {"aggregate": "median", "field": "precipitation"}
          }
        },
        {
          "mark": "point",
          "encoding": {
            "x": {"field": "temp_min", "bin": true},
            "y": {"field": "temp_max", "bin": true},
            "size": {"aggregate": "count"}
          }
        },
        {
          "mark": "point",
          "encoding": {
            "x": {"field": "temp_min", "bin": true},
            "y": {"field": "temp_max", "bin": true},
            "size": {"aggregate": "count"}
          }
        },
        {
          "mark": "point",
          "encoding": {
            "x": {"field": "temp_min", "bin": true},
            "y": {"field": "temp_max", "bin": true},
            "size": {"aggregate": "count"}
          }
        },
        {
          "mark": "point",
          "encoding": {
            "x": {"field": "temp_min", "bin": true},
            "y": {"field": "temp_max", "bin": true},
            "size": {"aggregate": "count"}
          }
        }
      ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-11
      • 1970-01-01
      • 2020-10-11
      • 2018-01-11
      • 1970-01-01
      相关资源
      最近更新 更多