This website is for Vega-Lite v2. Go to the main Vega-Lite homepage for the latest release.

Weekly Weather Plot

Inspired by this Vega example. Weekly weather data plot representing high/low ranges of record temperatures (light grey), average temperatures (dark grey), and both predicted and observed temperatures (black) for the given week. The first five days have high/low ranges of observed temperatures, and the last five days have ranges of predicted temperatures, where the upper barbell represents the range of high temperature predictions and the lower barbell represents the range of low temperature predictions. Created by @melissatdiamond.

View this example in the online editor

Vega-Lite JSON Specification

{
  "$schema":
  "https://vega.github.io/schema/vega-lite/v2.json",
  "description": "A layered bar chart with floating bars representing weekly weather data",
  "title": "Weekly Weather Observations and Predictions",
  "data":{
    "url": "data/weather.json" },
    "width": 250,
    "height": 200,
    "layer": [
      {
        "mark": {
          "type": "bar", "style": "box"
        },
        "encoding": {
          "y": {
            "field": "record.low",
            "type": "quantitative",
            "scale": {"domain": [10,70]},
            "axis": {"title": "Temperature (F)"}
          },
          "y2": {
            "field": "record.high",
            "type": "quantitative"
          },
          "x": {
            "field": "id",
            "type": "ordinal",
            "axis": {"title": "Day"}
          },
          "size": {"value": 20},
          "color": {"value": "#ccc"}
        }
      },
      {
        "mark": {
          "type": "bar", "style": "box"
        },
        "encoding": {
          "y": {
            "field": "normal.low",
            "type": "quantitative"
          },
          "y2": {
            "field": "normal.high",
            "type": "quantitative"
          },
          "x": {
            "field": "id",
            "type": "ordinal"
          },
          "size": {"value": 20},
          "color": {"value": "#999"}
        }
      },
      {
        "mark": {"type": "bar", "style": "box"},
        "encoding": {
          "y": {
            "field": "actual.low",
            "type": "quantitative"
          },
          "y2": {
            "field": "actual.high",
            "type": "quantitative"
          },
          "x": {
            "field": "id",
            "type": "ordinal"
          },
          "size": {"value": 12},
          "color": {"value": "#000"}
        }
      },
      {
        "mark": {"type": "bar", "style": "box"},
        "encoding": {
          "y": {
            "field": "forecast.low.low",
            "type": "quantitative"
          },
          "y2": {
            "field": "forecast.low.high",
            "type": "quantitative"
          },
          "x": {
            "field": "id",
            "type": "ordinal"
          },
          "size": {"value": 12},
          "color": {"value": "#000"}
        }
      },
      {
        "mark": {"type": "bar", "style": "box"},
        "encoding": {
          "y": {
            "field": "forecast.low.high",
            "type": "quantitative"
          },
          "y2": {
            "field": "forecast.high.low",
            "type": "quantitative"
          },
          "x": {
            "field": "id",
            "type": "ordinal"
          },
          "size": {"value": 3},
          "color": {"value": "#000"}
        }
      },
      {
        "mark": {"type": "bar", "style": "box"},
        "encoding": {
          "y": {
            "field": "forecast.high.low",
            "type": "quantitative"
          },
          "y2": {
            "field": "forecast.high.high",
            "type": "quantitative"
          },
          "x": {
            "field": "id",
            "type": "ordinal"
          },
          "size": {"value": 12},
          "color": {"value": "#000"}
        }
      },
      {
        "mark": {"type": "text", "align": "center", "dy": -105},
        "encoding": {
          "x": {
            "field": "id",
            "type": "ordinal",
            "axis": {
              "domain": false,
              "ticks": false,
              "labels": false,
              "title": "Day",
              "titlePadding": 25,
              "orient": "top"
            }
          },
          "text": {
            "field": "day",
            "type": "nominal"
          }
        }
      }
    ]
}