2017-07-18 121 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