Follow ______ on twitter.

2.2.3 Standard Deviation

Code

Vega-Lite Chart

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "config": {
    "view": {
      "continuousWidth": 250,
      "continuousHeight": 250
    }
  },
  "data": {
    "sequence": {
      "start": 1,
      "stop": 101,
      "step": 1,
      "as": "x"
    }
  },
  "transform": [
    {
      "calculate": "exp(20 * 0.01 + 10 * sqrt(0.01) * random())",
      "as": "y"
    }
  ],
  "hconcat": [
    {
      "title": "GBM Time Series",
      "width": 250,
      "height": 250,
      "layer": [
        {
          "mark": "line",
          "encoding": {
            "x": {
              "field": "x",
              "type": "quantitative",
              "axis": {
                "title": "Time"
              }
            },
            "y": {
              "field": "y",
              "type": "quantitative",
              "axis": {
                "title": "Value"
              },
              "scale": {
                "domain": [
                  1,
                  3.5
                ]
              }
            }
          }
        },
        {
          "mark": {
            "type": "rule",
            "color": "black",
            "strokeWidth": 1
          },
          "transform": [
            {
              "aggregate": [
                {
                  "op": "mean",
                  "field": "y",
                  "as": "mean_y"
                }
              ],
              "groupby": []
            }
          ],
          "encoding": {
            "y": {
              "field": "mean_y",
              "type": "quantitative"
            }
          }
        },
        {
          "mark": {
            "type": "rule",
            "color": "orange",
            "strokeDash": [
              4,
              4
            ],
            "strokeWidth": 4
          },
          "transform": [
            {
              "aggregate": [
                {
                  "op": "mean",
                  "field": "y",
                  "as": "mean_y"
                },
                {
                  "op": "stdev",
                  "field": "y",
                  "as": "stdev_y"
                }
              ],
              "groupby": []
            },
            {
              "calculate": "datum.mean_y + datum.stdev_y",
              "as": "upper"
            },
            {
              "calculate": "datum.mean_y - datum.stdev_y",
              "as": "lower"
            }
          ],
          "encoding": {
            "y": {
              "field": "upper",
              "type": "quantitative"
            }
          }
        },
        {
          "mark": {
            "type": "rule",
            "color": "orange",
            "strokeDash": [
              4,
              4
            ],
            "strokeWidth": 4
          },
          "transform": [
            {
              "aggregate": [
                {
                  "op": "mean",
                  "field": "y",
                  "as": "mean_y"
                },
                {
                  "op": "stdev",
                  "field": "y",
                  "as": "stdev_y"
                }
              ],
              "groupby": []
            },
            {
              "calculate": "datum.mean_y + datum.stdev_y",
              "as": "upper"
            },
            {
              "calculate": "datum.mean_y - datum.stdev_y",
              "as": "lower"
            }
          ],
          "encoding": {
            "y": {
              "field": "lower",
              "type": "quantitative"
            }
          }
        }
      ]
    },
    {
      "title": "Box Plot",
      "width": 250,
      "height": 250,
      "layer": [
        {
          "mark": {
            "type": "boxplot",
            "extent": "min-max",
            "median": {
              "color": "black"
            },
            "ticks": true
          },
          "encoding": {
            "y": {
              "field": "y",
              "type": "quantitative",
              "scale": {
                "domain": [
                  1,
                  3.5
                ]
              },
              "axis": {
                "title": "Value"
              }
            },
            "size": {
              "value": 60
            }
          }
        },
        {
          "mark": {
            "type": "rule",
            "color": "black",
            "strokeWidth": 1
          },
          "transform": [
            {
              "aggregate": [
                {
                  "op": "mean",
                  "field": "y",
                  "as": "mean_y"
                }
              ],
              "groupby": []
            }
          ],
          "encoding": {
            "y": {
              "field": "mean_y",
              "type": "quantitative"
            },
            "x": {
              "value": 0
            },
            "x2": {
              "value": 250
            }
          }
        },
        {
          "mark": {
            "type": "rule",
            "color": "orange",
            "strokeDash": [
              4,
              4
            ],
            "strokeWidth": 4
          },
          "transform": [
            {
              "aggregate": [
                {
                  "op": "mean",
                  "field": "y",
                  "as": "mean_y"
                },
                {
                  "op": "stdev",
                  "field": "y",
                  "as": "stdev_y"
                }
              ],
              "groupby": []
            },
            {
              "calculate": "datum.mean_y + datum.stdev_y",
              "as": "upper"
            },
            {
              "calculate": "datum.mean_y - datum.stdev_y",
              "as": "lower"
            }
          ],
          "encoding": {
            "y": {
              "field": "upper",
              "type": "quantitative"
            },
            "x": {
              "value": 0
            },
            "x2": {
              "value": 250
            }
          }
        },
        {
          "mark": {
            "type": "rule",
            "color": "orange",
            "strokeDash": [
              4,
              4
            ],
            "strokeWidth": 4
          },
          "transform": [
            {
              "aggregate": [
                {
                  "op": "mean",
                  "field": "y",
                  "as": "mean_y"
                },
                {
                  "op": "stdev",
                  "field": "y",
                  "as": "stdev_y"
                }
              ],
              "groupby": []
            },
            {
              "calculate": "datum.mean_y + datum.stdev_y",
              "as": "upper"
            },
            {
              "calculate": "datum.mean_y - datum.stdev_y",
              "as": "lower"
            }
          ],
          "encoding": {
            "y": {
              "field": "lower",
              "type": "quantitative"
            },
            "x": {
              "value": 0
            },
            "x2": {
              "value": 250
            }
          }
        }
      ]
    },
    {
      "title": "Histogram",
      "width": 250,
      "height": 250,
      "layer": [
        {
          "mark": "bar",
          "encoding": {
            "x": {
              "bin": {
                "maxbins": 30
              },
              "field": "y",
              "axis": {
                "title": "Value"
              },
              "scale": {
                "domain": [
                  1,
                  3.5
                ]
              }
            },
            "y": {
              "aggregate": "count",
              "axis": {
                "title": "Frequency"
              }
            }
          }
        },
        {
          "mark": {
            "type": "rule",
            "color": "black",
            "strokeWidth": 1
          },
          "transform": [
            {
              "aggregate": [
                {
                  "op": "mean",
                  "field": "y",
                  "as": "mean_y"
                }
              ],
              "groupby": []
            }
          ],
          "encoding": {
            "x": {
              "field": "mean_y",
              "type": "quantitative"
            }
          }
        },
        {
          "mark": {
            "type": "rule",
            "color": "orange",
            "strokeDash": [
              4,
              4
            ],
            "strokeWidth": 4
          },
          "transform": [
            {
              "aggregate": [
                {
                  "op": "mean",
                  "field": "y",
                  "as": "mean_y"
                },
                {
                  "op": "stdev",
                  "field": "y",
                  "as": "stdev_y"
                }
              ],
              "groupby": []
            },
            {
              "calculate": "datum.mean_y + datum.stdev_y",
              "as": "upper"
            },
            {
              "calculate": "datum.mean_y - datum.stdev_y",
              "as": "lower"
            }
          ],
          "encoding": {
            "x": {
              "field": "upper",
              "type": "quantitative"
            }
          }
        },
        {
          "mark": {
            "type": "rule",
            "color": "orange",
            "strokeDash": [
              4,
              4
            ],
            "strokeWidth": 4
          },
          "transform": [
            {
              "aggregate": [
                {
                  "op": "mean",
                  "field": "y",
                  "as": "mean_y"
                },
                {
                  "op": "stdev",
                  "field": "y",
                  "as": "stdev_y"
                }
              ],
              "groupby": []
            },
            {
              "calculate": "datum.mean_y + datum.stdev_y",
              "as": "upper"
            },
            {
              "calculate": "datum.mean_y - datum.stdev_y",
              "as": "lower"
            }
          ],
          "encoding": {
            "x": {
              "field": "lower",
              "type": "quantitative"
            }
          }
        }
      ]
    }
  ]
}