observablehq / plot

A concise API for exploratory data visualization implementing a layered grammar of graphics
https://observablehq.com/plot/
ISC License
4.38k stars 175 forks source link

Cumulative group? #200

Open mbostock opened 3 years ago

mbostock commented 3 years ago

I think the group transform could support a cumulative option, as the bin transform does. It’s less rarely needed since group is sometimes used with a categorical dimension, but it should make sense with an ordinal dimension.

mbostock commented 2 years ago

Example workaround using map and cumsum: https://observablehq.com/d/cc6eeed33e366ce8

untitled (40)

Plot.plot({
  marks: [
    Plot.areaY(movies, Plot.mapY("cumsum", Plot.groupX({y: "count"}, {x: "IMDB Rating"}))),
    Plot.ruleY([0])
  ]
})

Ref. https://talk.observablehq.com/t/how-to-translate-vega-lite-window-transform-grammar-to-pure-vega-lite-api-code/6679/4