{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "A error bar plot showing mean, min, and max in the US population distribution of age groups in 2000.", "background": "white", "padding": 5, "height": 200, "style": "cell", "data": [ { "name": "source_0", "url": "data/population.json", "format": {"type": "json", "parse": {"people": "number"}}, "transform": [ {"type": "filter", "expr": "datum.year == 2000"}, { "type": "aggregate", "groupby": ["age"], "ops": ["mean", "min", "max"], "fields": ["people", "people", "people"], "as": ["mean_people", "min_people", "max_people"] } ] }, { "name": "data_0", "source": "source_0", "transform": [ { "type": "filter", "expr": "isValid(datum[\"mean_people\"]) && isFinite(+datum[\"mean_people\"])" } ] }, { "name": "data_1", "source": "source_0", "transform": [ { "type": "filter", "expr": "isValid(datum[\"min_people\"]) && isFinite(+datum[\"min_people\"])" } ] }, { "name": "data_2", "source": "source_0", "transform": [ { "type": "filter", "expr": "isValid(datum[\"max_people\"]) && isFinite(+datum[\"max_people\"])" } ] } ], "signals": [ {"name": "x_step", "value": 20}, {"name": "width", "update": "bandspace(domain('x').length, 0, 0) * x_step"} ], "marks": [ { "name": "layer_0_marks", "type": "rule", "style": ["rule"], "from": {"data": "data_1"}, "encode": { "update": { "stroke": {"value": "black"}, "description": { "signal": "\"age: \" + (isValid(datum[\"age\"]) ? datum[\"age\"] : \"\"+datum[\"age\"]) + \"; population: \" + (format(datum[\"min_people\"], \"\")) + \"; Max of people: \" + (format(datum[\"max_people\"], \"\"))" }, "x": {"scale": "x", "field": "age", "band": 0.5}, "y": {"scale": "y", "field": "min_people"}, "y2": {"scale": "y", "field": "max_people"} } } }, { "name": "layer_1_marks", "type": "rect", "style": ["tick"], "from": {"data": "data_1"}, "encode": { "update": { "fill": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "tick"}, "description": { "signal": "\"age: \" + (isValid(datum[\"age\"]) ? datum[\"age\"] : \"\"+datum[\"age\"]) + \"; population: \" + (format(datum[\"min_people\"], \"\"))" }, "xc": {"scale": "x", "field": "age", "band": 0.5}, "yc": {"scale": "y", "field": "min_people"}, "width": {"value": 5}, "height": {"value": 1} } } }, { "name": "layer_2_marks", "type": "rect", "style": ["tick"], "from": {"data": "data_2"}, "encode": { "update": { "fill": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "tick"}, "description": { "signal": "\"age: \" + (isValid(datum[\"age\"]) ? datum[\"age\"] : \"\"+datum[\"age\"]) + \"; population: \" + (format(datum[\"max_people\"], \"\"))" }, "xc": {"scale": "x", "field": "age", "band": 0.5}, "yc": {"scale": "y", "field": "max_people"}, "width": {"value": 5}, "height": {"value": 1} } } }, { "name": "layer_3_marks", "type": "symbol", "style": ["point"], "from": {"data": "data_0"}, "encode": { "update": { "fill": {"value": "transparent"}, "stroke": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "point"}, "description": { "signal": "\"age: \" + (isValid(datum[\"age\"]) ? datum[\"age\"] : \"\"+datum[\"age\"]) + \"; population: \" + (format(datum[\"mean_people\"], \"\"))" }, "x": {"scale": "x", "field": "age", "band": 0.5}, "y": {"scale": "y", "field": "mean_people"}, "size": {"value": 2} } } } ], "scales": [ { "name": "x", "type": "band", "domain": { "fields": [ {"data": "data_1", "field": "age"}, {"data": "data_2", "field": "age"}, {"data": "data_0", "field": "age"} ], "sort": true }, "range": {"step": {"signal": "x_step"}}, "paddingInner": 0, "paddingOuter": 0 }, { "name": "y", "type": "linear", "domain": { "fields": [ {"data": "data_1", "field": "min_people"}, {"data": "data_1", "field": "max_people"}, {"data": "data_2", "field": "max_people"}, {"data": "data_0", "field": "mean_people"} ] }, "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": "age", "labelAlign": "right", "labelAngle": 270, "labelBaseline": "middle", "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "population", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ] }