1

按照 Vega-Lite 的西雅图天气教程,很容易按月绘制平均最低温度:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
  "data": {
    "url": "https://vega.github.io/vega-lite/data/seattle-weather.csv"
  },
  "mark": "line",
  "encoding": {
    "x": {
      "timeUnit": "month",
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "aggregate": "mean",
      "field": "temp_min",
      "type": "quantitative"
    }
  }
}

这个数据集也有temp_max变量。如何在 y 轴上绘制temp_min和绘制?temp_max

4

1 回答 1

5

您可以使用https://vega.github.io/vega-lite/docs/layer.html中所述的分层。

{
  "data": {"url": "data/seattle-weather.csv"},
  "layer": [
    {
      "mark": "line",
      "encoding": {
        "x": {
          "timeUnit": "month",
          "field": "date",
          "type": "temporal"
        },
        "y": {
          "aggregate": "mean",
          "field": "temp_min",
          "type": "quantitative"
        }
      }
    },
    {
      "mark": "line",
      "encoding": {
        "x": {
          "timeUnit": "month",
          "field": "date",
          "type": "temporal"
        },
        "y": {
          "aggregate": "mean",
          "field": "temp_max",
          "type": "quantitative"
        }
      }
    }
  ]
}

分层图表

于 2017-07-31T05:06:57.977 回答