Mix.install([
{:vega_lite, "~> 0.1.8"},
{:kino_vega_lite, "~> 0.1.10"},
{:jason, "~> 1.4"}
])
Vl.from_json("""
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"url": "https://vega.github.io/vega-lite/examples/data/movies.json"},
"transform": [{
"aggregate":[{"op": "count", "field": "*", "as": "count"}],
"groupby": ["IMDB Rating"]
},
{
"sort": [{"field": "IMDB Rating"}],
"window": [{"op": "sum", "field": "count", "as": "Cumulative Count"}],
"frame": [null, 0]
}],
"mark": "area",
"encoding": {
"x": {
"field": "IMDB Rating",
"type": "quantitative"
},
"y": {
"field": "Cumulative Count",
"type": "quantitative"
}
}
}
""")
Vl.new()
|> Vl.data_from_url("https://vega.github.io/vega-lite/examples/data/movies.json")
|> Vl.transform(aggregate: :count, field: "*", as: :count, groupby: ["IMDB Rating"])
|> Vl.transform(
window: :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)