{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "height": 200, "style": "cell", "data": [ { "name": "source_0", "url": "https://raw.githubusercontent.com/vega/vega-datasets/master/data/seattle-weather.csv", "format": {"type": "csv", "parse": {"date": "utc:'%Y-%m-%d'"}, "delimiter": ","}, "transform": [ { "field": "date", "type": "timeunit", "units": ["year"], "timezone": "utc", "as": ["year_date", "year_date_end"] }, { "type": "aggregate", "groupby": ["year_date", "weather"], "ops": ["count"], "fields": [null], "as": ["__count"] }, { "type": "stack", "groupby": ["year_date"], "field": "__count", "sort": {"field": ["weather"], "order": ["descending"]}, "as": ["__count_start", "__count_end"], "offset": "zero" } ] } ], "signals": [ {"name": "x_step", "value": 20}, { "name": "width", "update": "bandspace(domain('x').length, 0.1, 0.05) * x_step" } ], "marks": [ { "name": "marks", "type": "rect", "style": ["bar"], "from": {"data": "source_0"}, "encode": { "update": { "fill": {"scale": "color", "field": "weather"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"Month of the year: \" + (timeFormat(datum[\"year_date\"], timeUnitSpecifier([\"year\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"}))) + \"; Count of Records: \" + (format(datum[\"__count\"], \"\")) + \"; Weather type: \" + (isValid(datum[\"weather\"]) ? datum[\"weather\"] : \"\"+datum[\"weather\"])" }, "x": {"scale": "x", "field": "year_date"}, "width": {"scale": "x", "band": 1}, "y": {"scale": "y", "field": "__count_end"}, "y2": {"scale": "y", "field": "__count_start"} } } } ], "scales": [ { "name": "x", "type": "band", "domain": {"data": "source_0", "field": "year_date", "sort": true}, "range": {"step": {"signal": "x_step"}}, "paddingInner": 0.1, "paddingOuter": 0.05 }, { "name": "y", "type": "linear", "domain": { "data": "source_0", "fields": ["__count_start", "__count_end"] }, "range": [{"signal": "height"}, 0], "nice": true, "zero": true }, { "name": "color", "type": "ordinal", "domain": ["sun", "fog", "drizzle", "rain", "snow"], "range": ["#e7ba52", "#c7c7c7", "#aec7e8", "#1f77b4", "#9467bd"] } ], "axes": [ { "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": "Month of the year", "format": { "signal": "timeUnitSpecifier([\"year\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"})" }, "formatType": "utc", "labelOverlap": true, "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "Count of Records", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ], "legends": [ {"title": "Weather type", "fill": "color", "symbolType": "square"} ] }