2017-07-18 114 views
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_mintemp_max

回答

4

您可以按照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" 
     } 
     } 
    } 
    ] 
} 

layered chart