{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "Two horizonally concatenated charts that show a histogram of precipitation in Seattle and the relationship between min and max temperature.", "background": "white", "padding": 5, "height": 200, "data": [ { "name": "source_0", "url": "data/weather.csv", "format": {"type": "csv", "parse": {"date": "date"}}, "transform": [{"type": "filter", "expr": "datum.location === 'Seattle'"}] }, { "name": "data_0", "source": "source_0", "transform": [ { "field": "date", "type": "timeunit", "units": ["month"], "as": ["month_date", "month_date_end"] }, { "type": "aggregate", "groupby": ["month_date"], "ops": ["mean"], "fields": ["precipitation"], "as": ["mean_precipitation"] }, { "type": "filter", "expr": "isValid(datum[\"mean_precipitation\"]) && isFinite(+datum[\"mean_precipitation\"])" } ] }, { "name": "data_1", "source": "source_0", "transform": [ { "type": "extent", "field": "temp_min", "signal": "concat_1_bin_maxbins_10_temp_min_extent" }, { "type": "bin", "field": "temp_min", "as": ["bin_maxbins_10_temp_min", "bin_maxbins_10_temp_min_end"], "signal": "concat_1_bin_maxbins_10_temp_min_bins", "extent": {"signal": "concat_1_bin_maxbins_10_temp_min_extent"}, "maxbins": 10 }, { "type": "extent", "field": "temp_max", "signal": "concat_1_bin_maxbins_10_temp_max_extent" }, { "type": "bin", "field": "temp_max", "as": ["bin_maxbins_10_temp_max", "bin_maxbins_10_temp_max_end"], "signal": "concat_1_bin_maxbins_10_temp_max_bins", "extent": {"signal": "concat_1_bin_maxbins_10_temp_max_extent"}, "maxbins": 10 }, { "type": "aggregate", "groupby": [ "bin_maxbins_10_temp_min", "bin_maxbins_10_temp_min_end", "bin_maxbins_10_temp_max", "bin_maxbins_10_temp_max_end" ], "ops": ["count"], "fields": [null], "as": ["__count"] }, { "type": "filter", "expr": "isValid(datum[\"bin_maxbins_10_temp_min\"]) && isFinite(+datum[\"bin_maxbins_10_temp_min\"]) && isValid(datum[\"bin_maxbins_10_temp_max\"]) && isFinite(+datum[\"bin_maxbins_10_temp_max\"])" } ] } ], "signals": [ {"name": "concat_0_x_step", "value": 20}, { "name": "concat_0_width", "update": "bandspace(domain('concat_0_x').length, 0.1, 0.05) * concat_0_x_step" }, {"name": "concat_1_width", "value": 200} ], "layout": {"padding": 20, "bounds": "full", "align": "each"}, "marks": [ { "type": "group", "name": "concat_0_group", "style": "cell", "encode": { "update": { "width": {"signal": "concat_0_width"}, "height": {"signal": "height"} } }, "marks": [ { "name": "concat_0_marks", "type": "rect", "style": ["bar"], "from": {"data": "data_0"}, "encode": { "update": { "fill": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"date (month): \" + (timeFormat(datum[\"month_date\"], timeUnitSpecifier([\"month\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"}))) + \"; Mean of precipitation: \" + (format(datum[\"mean_precipitation\"], \"\"))" }, "x": {"scale": "concat_0_x", "field": "month_date"}, "width": {"scale": "concat_0_x", "band": 1}, "y": {"scale": "concat_0_y", "field": "mean_precipitation"}, "y2": {"scale": "concat_0_y", "value": 0} } } } ], "axes": [ { "scale": "concat_0_y", "orient": "left", "gridScale": "concat_0_x", "grid": true, "tickCount": {"signal": "ceil(height/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 }, { "scale": "concat_0_x", "orient": "bottom", "grid": false, "title": "date (month)", "format": { "signal": "timeUnitSpecifier([\"month\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"})" }, "formatType": "time", "labelOverlap": true, "zindex": 0 }, { "scale": "concat_0_y", "orient": "left", "grid": false, "title": "Mean of precipitation", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ] }, { "type": "group", "name": "concat_1_group", "style": "cell", "encode": { "update": { "width": {"signal": "concat_1_width"}, "height": {"signal": "height"} } }, "marks": [ { "name": "concat_1_marks", "type": "symbol", "style": ["point"], "from": {"data": "data_1"}, "encode": { "update": { "fill": {"value": "transparent"}, "stroke": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "point"}, "description": { "signal": "\"temp_min (binned): \" + (!isValid(datum[\"bin_maxbins_10_temp_min\"]) || !isFinite(+datum[\"bin_maxbins_10_temp_min\"]) ? \"null\" : format(datum[\"bin_maxbins_10_temp_min\"], \"\") + \" – \" + format(datum[\"bin_maxbins_10_temp_min_end\"], \"\")) + \"; temp_max (binned): \" + (!isValid(datum[\"bin_maxbins_10_temp_max\"]) || !isFinite(+datum[\"bin_maxbins_10_temp_max\"]) ? \"null\" : format(datum[\"bin_maxbins_10_temp_max\"], \"\") + \" – \" + format(datum[\"bin_maxbins_10_temp_max_end\"], \"\")) + \"; Count of Records: \" + (format(datum[\"__count\"], \"\"))" }, "x": { "signal": "scale(\"concat_1_x\", 0.5 * datum[\"bin_maxbins_10_temp_min\"] + 0.5 * datum[\"bin_maxbins_10_temp_min_end\"])" }, "y": { "signal": "scale(\"concat_1_y\", 0.5 * datum[\"bin_maxbins_10_temp_max\"] + 0.5 * datum[\"bin_maxbins_10_temp_max_end\"])" }, "size": {"scale": "size", "field": "__count"} } } } ], "axes": [ { "scale": "concat_1_x", "orient": "bottom", "grid": false, "title": "temp_min (binned)", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(concat_1_width/10)"}, "zindex": 0 }, { "scale": "concat_1_y", "orient": "left", "grid": false, "title": "temp_max (binned)", "labelOverlap": true, "tickCount": {"signal": "ceil(height/10)"}, "zindex": 0 } ] } ], "scales": [ { "name": "size", "type": "linear", "domain": {"data": "data_1", "field": "__count"}, "range": [ 0, { "signal": "pow(0.95 * min(concat_1_width / ((concat_1_bin_maxbins_10_temp_min_bins.stop - concat_1_bin_maxbins_10_temp_min_bins.start) / concat_1_bin_maxbins_10_temp_min_bins.step), height / ((concat_1_bin_maxbins_10_temp_max_bins.stop - concat_1_bin_maxbins_10_temp_max_bins.start) / concat_1_bin_maxbins_10_temp_max_bins.step)), 2)" } ], "zero": true }, { "name": "concat_0_x", "type": "band", "domain": {"data": "data_0", "field": "month_date", "sort": true}, "range": {"step": {"signal": "concat_0_x_step"}}, "paddingInner": 0.1, "paddingOuter": 0.05 }, { "name": "concat_0_y", "type": "linear", "domain": {"data": "data_0", "field": "mean_precipitation"}, "range": [{"signal": "height"}, 0], "nice": true, "zero": true }, { "name": "concat_1_x", "type": "linear", "domain": { "signal": "[concat_1_bin_maxbins_10_temp_min_bins.start, concat_1_bin_maxbins_10_temp_min_bins.stop]" }, "range": [0, {"signal": "concat_1_width"}], "bins": {"signal": "concat_1_bin_maxbins_10_temp_min_bins"}, "zero": false }, { "name": "concat_1_y", "type": "linear", "domain": { "signal": "[concat_1_bin_maxbins_10_temp_max_bins.start, concat_1_bin_maxbins_10_temp_max_bins.stop]" }, "range": [{"signal": "height"}, 0], "bins": {"signal": "concat_1_bin_maxbins_10_temp_max_bins"}, "zero": false } ], "legends": [ { "size": "size", "symbolType": "circle", "title": "Count of Records", "encode": { "symbols": { "update": { "fill": {"value": "transparent"}, "stroke": {"value": "#4c78a8"} } } } } ] }