How to plot several variables on an axis with Vega-Lite?

空扰寡人 提交于 2019-12-04 05:19:46

问题


Following Vega-Lite's Seattle weather tutorial, it was easy to plot avg min temperature by month:

{
  "$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"
    }
  }
}

This dataset also has temp_max variable. How can I plot both temp_min and temp_max on y-axis?


回答1:


You can use layering as described at 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"
        }
      }
    }
  ]
}



来源:https://stackoverflow.com/questions/45160007/how-to-plot-several-variables-on-an-axis-with-vega-lite

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!