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

Error Bars showing Standard Deviation

View this example in the online editor

Vega-Lite JSON Specification

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
  "data": {"url": "data/barley.json"},

  "transform": [
    {
      "aggregate": [
        {"op": "mean", "field": "yield", "as": "mean"},
        {"op": "stdev", "field": "yield", "as": "stdev"}
      ],
      "groupby": ["variety"]
    },
    {
      "calculate": "datum.mean-datum.stdev",
      "as": "lower"
    },
    {
      "calculate": "datum.mean+datum.stdev",
      "as": "upper"
    }
  ],
  "layer": [{
    "mark": {"type": "point", "filled": true},
    "encoding": {
      "x": {
        "field": "mean", "type": "quantitative",
        "scale": {"zero": false},
        "axis": {"title": "Barley Yield"}
      },
      "y": {"field": "variety", "type": "ordinal"},
      "color": {"value": "black"}
    }
  }, {
    "mark": "rule",
    "encoding": {
      "x": {"field": "upper", "type": "quantitative"},
      "x2": {"field": "lower", "type": "quantitative"},
      "y": {"field": "variety", "type": "ordinal"}
    }
  }]
}