Skip to content

Instantly share code, notes, and snippets.

@cigrainger
Created October 19, 2023 10:56
Show Gist options
  • Save cigrainger/9fe3eda3b74d207ead4401a1211ac937 to your computer and use it in GitHub Desktop.
Save cigrainger/9fe3eda3b74d207ead4401a1211ac937 to your computer and use it in GitHub Desktop.

Untitled notebook

Mix.install([
  {:vega_lite, "~> 0.1.8"},
  {:kino_vega_lite, "~> 0.1.10"},
  {:jason, "~> 1.4"}
])

Section

alias VegaLite, as: Vl
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment