Follow ______ on twitter.

2.2.4 Interquartile Range (IQR)

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": "red"
          },
          "encoding": {
            "y": {
              "aggregate": "q3",
              "field": "y"
            }
          }
        },
        {
          "mark": {
            "type": "rule",
            "color": "green"
          },
          "encoding": {
            "y": {
              "aggregate": "q1",
              "field": "y"
            }
          }
        },
        {
          "mark": {
            "type": "rule",
            "color": "blue"
          },
          "encoding": {
            "y": {
              "aggregate": "q1",
              "field": "y"
            },
            "y2": {
              "aggregate": "q3",
              "field": "y"
            },
            "x": {
              "value": 150
            }
          }
        },
        {
          "mark": {
            "type": "text",
            "align": "left",
            "dx": 15
          },
          "encoding": {
            "y": {
              "aggregate": "q3",
              "field": "y"
            },
            "text": {
              "aggregate": "q3",
              "field": "y",
              "format": ".2f"
            }
          }
        },
        {
          "mark": {
            "type": "text",
            "align": "left",
            "dx": 15
          },
          "encoding": {
            "y": {
              "aggregate": "q1",
              "field": "y"
            },
            "text": {
              "aggregate": "q1",
              "field": "y",
              "format": ".2f"
            }
          }
        },
        {
          "mark": {
            "type": "text",
            "align": "left",
            "dx": 15,
            "dy": 20
          },
          "encoding": {
            "y": {
              "aggregate": "mean",
              "field": "y"
            },
            "text": {
              "calculate": "format(datum.max_y - datum.min_y, '.2f')",
              "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": "blue"
          },
          "encoding": {
            "y": {
              "aggregate": "q1",
              "field": "y"
            },
            "y2": {
              "aggregate": "q3",
              "field": "y"
            },
            "x": {
              "value": 200
            }
          }
        },
        {
          "mark": {
            "type": "text",
            "align": "left",
            "dx": 65
          },
          "encoding": {
            "y": {
              "aggregate": "q3",
              "field": "y"
            },
            "text": {
              "aggregate": "q3",
              "field": "y",
              "format": ".2f"
            }
          }
        },
        {
          "mark": {
            "type": "text",
            "align": "left",
            "dx": 65
          },
          "encoding": {
            "y": {
              "aggregate": "q1",
              "field": "y"
            },
            "text": {
              "aggregate": "q1",
              "field": "y",
              "format": ".2f"
            }
          }
        },
        {
          "mark": {
            "type": "text",
            "align": "left",
            "dx": 65
          },
          "encoding": {
            "y": {
              "aggregate": "mean",
              "field": "y"
            },
            "text": {
              "calculate": "format(datum.max_y - datum.min_y, '.2f')",
              "type": "quantitative"
            }
          }
        }
      ]
    },
    {
      "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": "red"
          },
          "encoding": {
            "x": {
              "aggregate": "q3",
              "field": "y"
            }
          }
        },
        {
          "mark": {
            "type": "rule",
            "color": "green"
          },
          "encoding": {
            "x": {
              "aggregate": "q1",
              "field": "y"
            }
          }
        },
        {
          "mark": {
            "type": "rule",
            "color": "blue"
          },
          "encoding": {
            "x": {
              "aggregate": "q1",
              "field": "y"
            },
            "x2": {
              "aggregate": "q3",
              "field": "y"
            },
            "y": {
              "value": 20
            }
          }
        },
        {
          "mark": {
            "type": "text",
            "align": "left",
            "dx": -10,
            "dy": 5
          },
          "encoding": {
            "x": {
              "aggregate": "q3",
              "field": "y"
            },
            "y": {
              "value": 0
            },
            "text": {
              "aggregate": "q3",
              "field": "y",
              "format": ".2f"
            }
          }
        },
        {
          "mark": {
            "type": "text",
            "align": "right",
            "dx": 10,
            "dy": 5
          },
          "encoding": {
            "x": {
              "aggregate": "q1",
              "field": "y"
            },
            "y": {
              "value": 0
            },
            "text": {
              "aggregate": "q1",
              "field": "y",
              "format": ".2f"
            }
          }
        },
        {
          "mark": {
            "type": "text",
            "align": "center",
            "dy": 20
          },
          "encoding": {
            "x": {
              "aggregate": "mean",
              "field": "y"
            },
            "y": {
              "value": 0
            },
            "text": {
              "calculate": "format(datum.max_y - datum.min_y, '.2f')",
              "type": "quantitative"
            }
          }
        }
      ]
    }
  ]
}