{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "width": 200, "style": "cell", "data": [ { "name": "source_0", "url": "data/movies.json", "format": {"type": "json"}, "transform": [ {"type": "filter", "expr": "datum['IMDB Rating'] != null"}, { "type": "joinaggregate", "as": ["AverageRating"], "ops": ["mean"], "fields": ["IMDB Rating"] }, { "type": "filter", "expr": "(datum['IMDB Rating'] - datum.AverageRating) > 2.5" } ] }, { "name": "data_0", "source": "source_0", "transform": [ { "type": "stack", "groupby": ["Title"], "field": "IMDB Rating", "sort": {"field": [], "order": []}, "as": ["IMDB Rating_start", "IMDB Rating_end"], "offset": "zero" }, { "type": "filter", "expr": "isValid(datum[\"IMDB Rating\"]) && isFinite(+datum[\"IMDB Rating\"])" } ] }, { "name": "data_1", "source": "source_0", "transform": [ { "type": "aggregate", "groupby": [], "ops": ["average"], "fields": ["AverageRating"], "as": ["average_AverageRating"] }, { "type": "filter", "expr": "isValid(datum[\"average_AverageRating\"]) && isFinite(+datum[\"average_AverageRating\"])" } ] } ], "signals": [ {"name": "y_step", "value": 20}, { "name": "height", "update": "bandspace(domain('y').length, 0.1, 0.05) * y_step" } ], "marks": [ { "name": "layer_0_marks", "type": "rect", "style": ["bar"], "from": {"data": "data_0"}, "encode": { "update": { "fill": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"IMDB Rating: \" + (format(datum[\"IMDB Rating\"], \"\")) + \"; Title: \" + (isValid(datum[\"Title\"]) ? datum[\"Title\"] : \"\"+datum[\"Title\"])" }, "x": {"scale": "x", "field": "IMDB Rating_end"}, "x2": {"scale": "x", "field": "IMDB Rating_start"}, "y": {"scale": "y", "field": "Title"}, "height": {"scale": "y", "band": 1} } } }, { "name": "layer_1_marks", "type": "rule", "style": ["rule"], "from": {"data": "data_1"}, "encode": { "update": { "stroke": {"value": "red"}, "description": { "signal": "\"Average of AverageRating: \" + (format(datum[\"average_AverageRating\"], \"\"))" }, "x": {"scale": "x", "field": "average_AverageRating"}, "y": {"value": 0}, "y2": {"field": {"group": "height"}} } } } ], "scales": [ { "name": "x", "type": "linear", "domain": { "fields": [ {"data": "data_0", "field": "IMDB Rating_start"}, {"data": "data_0", "field": "IMDB Rating_end"}, {"data": "data_1", "field": "average_AverageRating"} ] }, "range": [0, {"signal": "width"}], "nice": true, "zero": true }, { "name": "y", "type": "band", "domain": {"data": "data_0", "field": "Title", "sort": true}, "range": {"step": {"signal": "y_step"}}, "paddingInner": 0.1, "paddingOuter": 0.05 } ], "axes": [ { "scale": "x", "orient": "bottom", "gridScale": "y", "grid": true, "tickCount": {"signal": "ceil(width/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 }, { "scale": "x", "orient": "bottom", "grid": false, "title": "IMDB Rating", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(width/40)"}, "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "Title", "zindex": 0 } ] }