livebook-dev / vega_lite

Elixir bindings for Vega-Lite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cumulative aggregations

cigrainger opened this issue · comments

I'm trying to figure out a cumulative count aggregation and I'm stumbling over the aggregate and window transforms. Here's a Livebook where I'm trying to replicate the example here. I can't seem to get the correct incantation of transforms down. Any help would be greatly appreciated. 🙏 I'm happy to add the examples back via a PR.

https://gist.github.com/cigrainger/9fe3eda3b74d207ead4401a1211ac937

Here's the corresponding Vl :)

Vl.new()
|> Vl.data_from_url("https://vega.github.io/vega-lite/examples/data/movies.json")
|> Vl.transform(aggregate: [[op: :count, field: "*", as: :count]], groupby: ["IMDB Rating"])
|> Vl.transform(
  window: [[op: :sum, field: :count, as: "Cumulative Count"]],
  sort: [[field: "IMDB Rating"]],
  frame: [nil, 0]
)
|> Vl.mark(:area)
|> Vl.encode_field(:x, "IMDB Rating", type: :quantitative)
|> Vl.encode_field(:y, "Cumulative Count", type: :quantitative)

Oh wow. Thanks! Why do they need to be double wrapped? I tried that way first but didn't double wrap the keyword lists so was getting window.map is not iterable or similar.

Nevermind I see it now -- it's an object inside an array. My eyes must have just glossed over this. Thanks again @jonatanklosko.