{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "A line graph showing how the overall average Miles Per Gallon for how the MPG has changed over the years. The red line shows the average, and is layered on top of all the raw data.", "background": "white", "padding": 5, "width": 200, "height": 200, "style": "cell", "data": [ { "name": "source_0", "url": "https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json", "format": {"type": "json", "parse": {"Year": "date"}}, "transform": [ {"type": "filter", "expr": "datum.Miles_per_Gallon !== null"}, { "field": "Year", "type": "timeunit", "units": ["year"], "timezone": "utc", "as": ["year", "year_end"] }, { "type": "window", "params": [1], "as": ["Average_MPG"], "ops": ["mean"], "fields": ["Miles_per_Gallon"], "sort": {"field": ["year"], "order": ["ascending"]}, "ignorePeers": false, "frame": [null, 0] }, { "field": "Year", "type": "timeunit", "units": ["year"], "timezone": "utc", "as": ["year_Year", "year_Year_end"] } ] }, { "name": "data_0", "source": "source_0", "transform": [ { "type": "filter", "expr": "(isDate(datum[\"year_Year\"]) || (isValid(datum[\"year_Year\"]) && isFinite(+datum[\"year_Year\"]))) && isValid(datum[\"Miles_per_Gallon\"]) && isFinite(+datum[\"Miles_per_Gallon\"])" } ] } ], "marks": [ { "name": "layer_0_marks", "type": "symbol", "style": ["circle"], "from": {"data": "data_0"}, "encode": { "update": { "opacity": {"value": 0.7}, "fill": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "circle"}, "description": { "signal": "\"Year (year): \" + (timeFormat(datum[\"year_Year\"], timeUnitSpecifier([\"year\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"}))) + \"; Miles_per_Gallon: \" + (format(datum[\"Miles_per_Gallon\"], \"\"))" }, "x": {"scale": "x", "field": "year_Year"}, "y": {"scale": "y", "field": "Miles_per_Gallon"}, "shape": {"value": "circle"} } } }, { "name": "layer_1_marks", "type": "line", "style": ["line"], "sort": {"field": "datum[\"year_Year\"]"}, "from": {"data": "source_0"}, "encode": { "update": { "stroke": {"value": "red"}, "description": { "signal": "\"Year (year): \" + (timeFormat(datum[\"year_Year\"], timeUnitSpecifier([\"year\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"}))) + \"; Miles Per Gallon: \" + (format(datum[\"Average_MPG\"], \"\"))" }, "x": {"scale": "x", "field": "year_Year"}, "y": {"scale": "y", "field": "Average_MPG"}, "defined": { "signal": "isValid(datum[\"year_Year\"]) && isFinite(+datum[\"year_Year\"]) && isValid(datum[\"Average_MPG\"]) && isFinite(+datum[\"Average_MPG\"])" } } } } ], "scales": [ { "name": "x", "type": "time", "domain": { "fields": [ {"data": "data_0", "field": "year_Year"}, {"data": "source_0", "field": "year_Year"} ] }, "range": [0, {"signal": "width"}] }, { "name": "y", "type": "linear", "domain": { "fields": [ {"data": "data_0", "field": "Miles_per_Gallon"}, {"data": "source_0", "field": "Average_MPG"} ] }, "range": [{"signal": "height"}, 0], "nice": true, "zero": true } ], "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": "y", "orient": "left", "gridScale": "x", "grid": true, "tickCount": {"signal": "ceil(height/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 }, { "scale": "x", "orient": "bottom", "grid": false, "title": "Year (year)", "format": { "signal": "timeUnitSpecifier([\"year\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"})" }, "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(width/40)"}, "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "Miles Per Gallon", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ] }