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

Layered Histogram and Cumulative Histogram

View this example in the online editor

Vega-Lite JSON Specification

{
  "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
  "data": {"url": "data/movies.json"},
  "transform": [{
    "bin": true,
    "field": "IMDB_Rating",
    "as": "bin_IMDB_Rating"
  }, {
    "aggregate": [{"op": "count", "as": "count"}],
    "groupby": ["bin_IMDB_Rating", "bin_IMDB_Rating_end"]
  }, {
    "filter": "datum.bin_IMDB_Rating !== null"
  }, {
    "sort": [{"field": "bin_IMDB_Rating"}],
    "window": [{"op": "sum", "field": "count", "as": "cumulative_count"}],
    "frame": [null, 0]
  }],
  "encoding": {
    "x": {
      "field": "bin_IMDB_Rating", "type": "quantitative",
      "scale": {"zero": false},
      "title": "IMDB Rating"
    },
    "x2": {"field": "bin_IMDB_Rating_end"}
  },
  "layer": [{
    "mark": "bar",
    "encoding": {
      "y": {"field": "cumulative_count", "type": "quantitative"}
    }
  }, {
    "mark": {"type": "bar", "color": "yellow", "opacity": 0.5},
    "encoding": {
      "y": {"field": "count", "type": "quantitative"}
    }
  }]
}