{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "The PM2.5 value of Beijing observed 15 days, highlighting the days when PM2.5 level is hazardous to human health. Data source https://chartaccent.github.io/chartaccent.html", "background": "white", "padding": 5, "height": 200, "style": "cell", "data": [ { "name": "source_0", "values": [ {"Day": 1, "Value": 54.8}, {"Day": 2, "Value": 112.1}, {"Day": 3, "Value": 63.6}, {"Day": 4, "Value": 37.6}, {"Day": 5, "Value": 79.7}, {"Day": 6, "Value": 137.9}, {"Day": 7, "Value": 120.1}, {"Day": 8, "Value": 103.3}, {"Day": 9, "Value": 394.8}, {"Day": 10, "Value": 199.5}, {"Day": 11, "Value": 72.3}, {"Day": 12, "Value": 51.1}, {"Day": 13, "Value": 112}, {"Day": 14, "Value": 174.5}, {"Day": 15, "Value": 130.5} ] }, {"name": "source_1", "values": [{}]}, { "name": "data_1", "source": "source_0", "transform": [ { "type": "stack", "groupby": ["Day"], "field": "Value", "sort": {"field": [], "order": []}, "as": ["Value_start", "Value_end"], "offset": "zero" }, { "type": "filter", "expr": "isValid(datum[\"Value\"]) && isFinite(+datum[\"Value\"])" } ] }, { "name": "data_2", "source": "source_0", "transform": [ {"type": "filter", "expr": "datum.Value >= 300"}, {"type": "formula", "expr": "300", "as": "baseline"}, { "type": "filter", "expr": "isValid(datum[\"baseline\"]) && isFinite(+datum[\"baseline\"])" } ] } ], "signals": [ {"name": "x_step", "value": 20}, { "name": "width", "update": "bandspace(domain('x').length, 0.1, 0.05) * x_step" } ], "marks": [ { "name": "layer_0_layer_0_marks", "type": "rect", "style": ["bar"], "from": {"data": "data_1"}, "encode": { "update": { "fill": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"Day: \" + (isValid(datum[\"Day\"]) ? datum[\"Day\"] : \"\"+datum[\"Day\"]) + \"; Value: \" + (format(datum[\"Value\"], \"\"))" }, "x": {"scale": "x", "field": "Day"}, "width": {"scale": "x", "band": 1}, "y": {"scale": "y", "field": "Value_end"}, "y2": {"scale": "y", "field": "Value_start"} } } }, { "name": "layer_0_layer_1_marks", "type": "rect", "style": ["bar"], "from": {"data": "data_2"}, "encode": { "update": { "fill": {"value": "#e45755"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"Day: \" + (isValid(datum[\"Day\"]) ? datum[\"Day\"] : \"\"+datum[\"Day\"]) + \"; PM2.5 Value: \" + (format(datum[\"baseline\"], \"\")) + \"; Value: \" + (format(datum[\"Value\"], \"\"))" }, "x": {"scale": "x", "field": "Day"}, "width": {"scale": "x", "band": 1}, "y": {"scale": "y", "field": "baseline"}, "y2": {"scale": "y", "field": "Value"} } } }, { "name": "layer_1_layer_0_marks", "type": "rule", "style": ["rule"], "from": {"data": "source_1"}, "encode": { "update": { "stroke": {"value": "black"}, "x": {"field": {"group": "width"}}, "x2": {"value": 0}, "y": {"scale": "y", "value": 300} } } }, { "name": "layer_1_layer_1_marks", "type": "text", "style": ["text"], "from": {"data": "source_1"}, "encode": { "update": { "align": {"value": "right"}, "baseline": {"value": "bottom"}, "text": {"value": "hazardous"}, "dx": {"value": -2}, "dy": {"value": -2}, "fill": {"value": "black"}, "x": {"field": {"group": "width"}}, "y": {"scale": "y", "value": 300} } } } ], "scales": [ { "name": "x", "type": "band", "domain": { "fields": [ {"data": "data_1", "field": "Day"}, {"data": "data_2", "field": "Day"} ], "sort": true }, "range": {"step": {"signal": "x_step"}}, "paddingInner": 0.1, "paddingOuter": 0.05 }, { "name": "y", "type": "linear", "domain": { "fields": [ {"data": "data_1", "field": "Value_start"}, {"data": "data_1", "field": "Value_end"}, {"data": "data_2", "field": "baseline"}, {"data": "data_2", "field": "Value"}, [300] ] }, "range": [{"signal": "height"}, 0], "nice": true, "zero": true } ], "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": "Day", "labelAngle": 0, "labelBaseline": "top", "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "PM2.5 Value", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ] }