Skip to content

Instantly share code, notes, and snippets.

@domoritz
Created May 10, 2020 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domoritz/1efe73556e1f1e88cc5a9847fee7e6b8 to your computer and use it in GitHub Desktop.
Save domoritz/1efe73556e1f1e88cc5a9847fee7e6b8 to your computer and use it in GitHub Desktop.
Window smoothing with filter
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {"sequence": {"start": 0, "stop": 100, "as": "x"}},
"transform": [{"calculate": "random() * sin(datum.x/10)", "as": "y"}],
"vconcat": [
{
"width": 600,
"mark": "line",
"encoding": {
"x": {"field": "x", "type": "quantitative"},
"y": {"field": "y", "type": "quantitative"}
}
},
{
"width": 600,
"transform": [
{"filter": "datum.x < end"},
{
"window": [{"field": "y", "op": "mean", "as": "mean"}],
"frame": [-10, 10]
}
],
"mark": "line",
"encoding": {
"x": {
"field": "x",
"type": "quantitative",
"scale": {"domain": [0, 100]}
},
"y": {"field": "mean", "type": "quantitative"}
}
}
],
"config": {
"signals": [{"name": "end", "value": 50, "bind": {"type": "range"}}]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment