{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "Bar graph showing the best films for the year they were produced, where best is defined by at least 2.5 points above average for that year. The red point shows the average rating for a film in that year, and the bar is the rating that the film recieved.", "background": "white", "padding": 5, "width": 200, "style": "cell", "data": [ { "name": "source_0", "url": "https://raw.githubusercontent.com/vega/vega-datasets/master/data/movies.json", "format": {"type": "json", "parse": {"Release Date": "date"}}, "transform": [ {"type": "filter", "expr": "datum['IMDB Rating'] != null"}, { "field": "Release Date", "type": "timeunit", "units": ["year"], "as": ["year", "year_end"] }, { "type": "joinaggregate", "as": ["AverageYearRating"], "ops": ["mean"], "fields": ["IMDB Rating"], "groupby": ["year"] }, { "type": "filter", "expr": "(datum['IMDB Rating'] - datum.AverageYearRating) > 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": "filter", "expr": "isValid(datum[\"AverageYearRating\"]) && isFinite(+datum[\"AverageYearRating\"])" } ] } ], "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", "clip": true, "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": "rect", "style": ["tick"], "from": {"data": "data_1"}, "encode": { "update": { "opacity": {"value": 0.7}, "fill": {"value": "red"}, "ariaRoleDescription": {"value": "tick"}, "description": { "signal": "\"AverageYearRating: \" + (format(datum[\"AverageYearRating\"], \"\")) + \"; Title: \" + (isValid(datum[\"Title\"]) ? datum[\"Title\"] : \"\"+datum[\"Title\"])" }, "xc": {"scale": "x", "field": "AverageYearRating"}, "yc": {"scale": "y", "field": "Title", "band": 0.5}, "height": {"value": 15}, "width": {"value": 1} } } } ], "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": "AverageYearRating"} ] }, "range": [0, {"signal": "width"}], "nice": true, "zero": true }, { "name": "y", "type": "band", "domain": { "fields": [ {"data": "data_0", "field": "Title"}, {"data": "data_1", "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 } ] }