{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "A dual axis chart, created by setting y's scale resolution to `\"independent\"`", "background": "white", "padding": 5, "width": 400, "height": 300, "style": "cell", "data": [ { "name": "source_0", "url": "data/weather.csv", "format": {"type": "csv", "parse": {"date": "date"}}, "transform": [ {"type": "filter", "expr": "datum.location == \"Seattle\""}, { "field": "date", "type": "timeunit", "units": ["month"], "as": ["month_date", "month_date_end"] }, { "type": "aggregate", "groupby": ["month_date"], "ops": ["average", "average", "average"], "fields": ["temp_max", "temp_min", "precipitation"], "as": [ "average_temp_max", "average_temp_min", "average_precipitation" ] } ] } ], "marks": [ { "name": "layer_0_marks", "type": "area", "style": ["area"], "sort": {"field": "datum[\"month_date\"]"}, "from": {"data": "source_0"}, "encode": { "update": { "opacity": {"value": 0.3}, "orient": {"value": "vertical"}, "fill": {"value": "#85C5A6"}, "description": { "signal": "\"date (month): \" + (timeFormat(datum[\"month_date\"], '%b')) + \"; Avg. Temperature (°C): \" + (format(datum[\"average_temp_max\"], \"\")) + \"; Average of temp_min: \" + (format(datum[\"average_temp_min\"], \"\"))" }, "x": {"scale": "x", "field": "month_date"}, "y": {"scale": "layer_0_y", "field": "average_temp_max"}, "y2": {"scale": "layer_0_y", "field": "average_temp_min"}, "defined": { "signal": "isValid(datum[\"month_date\"]) && isFinite(+datum[\"month_date\"]) && isValid(datum[\"average_temp_max\"]) && isFinite(+datum[\"average_temp_max\"])" } } } }, { "name": "layer_1_marks", "type": "line", "style": ["line"], "sort": {"field": "datum[\"month_date\"]"}, "from": {"data": "source_0"}, "encode": { "update": { "stroke": {"value": "#85A9C5"}, "interpolate": {"value": "monotone"}, "description": { "signal": "\"date (month): \" + (timeFormat(datum[\"month_date\"], '%b')) + \"; Precipitation (inches): \" + (format(datum[\"average_precipitation\"], \"\"))" }, "x": {"scale": "x", "field": "month_date"}, "y": {"scale": "layer_1_y", "field": "average_precipitation"}, "defined": { "signal": "isValid(datum[\"month_date\"]) && isFinite(+datum[\"month_date\"]) && isValid(datum[\"average_precipitation\"]) && isFinite(+datum[\"average_precipitation\"])" } } } } ], "scales": [ { "name": "x", "type": "time", "domain": {"data": "source_0", "field": "month_date"}, "range": [0, {"signal": "width"}] }, { "name": "layer_0_y", "type": "linear", "domain": [0, 30], "range": [{"signal": "height"}, 0], "zero": true }, { "name": "layer_1_y", "type": "linear", "domain": {"data": "source_0", "field": "average_precipitation"}, "range": [{"signal": "height"}, 0], "nice": true, "zero": true } ], "axes": [ { "scale": "x", "orient": "bottom", "gridScale": "layer_0_y", "grid": true, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 }, { "scale": "x", "orient": "bottom", "grid": false, "format": "%b", "labelFlush": true, "labelOverlap": true, "zindex": 0 }, { "scale": "layer_0_y", "orient": "left", "grid": false, "title": "Avg. Temperature (°C)", "titleColor": "#85C5A6", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 }, { "scale": "layer_1_y", "orient": "right", "grid": false, "title": "Precipitation (inches)", "titleColor": "#85A9C5", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ] }