Calculate Difference from Average
View this example in the online editor
Vega-Lite JSON Specification
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"data": {"url": "data/movies.json"},
"transform": [
{"filter": "datum.IMDB_Rating != null"},
{
"window": [{
"op": "mean",
"field": "IMDB_Rating",
"as": "AverageRating"
}],
"frame": [
null,
null
]
},
{"filter": "(datum.IMDB_Rating - datum.AverageRating) > 2.5"}
],
"layer": [
{
"mark": "bar",
"encoding": {
"x": {
"field": "IMDB_Rating", "type": "quantitative",
"axis": {"title": "IMDB Rating"}
},
"y": {"field": "Title", "type": "ordinal"}
}
},
{
"mark": {"type": "rule", "color": "red"},
"encoding": {
"x": {
"aggregate": "average",
"field": "AverageRating",
"type": "quantitative"
}
}
}
]
}