{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "A bar chart showing the US population distribution of age groups in 2000.", "background": "white", "padding": 5, "width": 200, "style": "cell", "data": [ { "name": "source_0", "url": "data/population.json", "format": {"type": "json"}, "transform": [ {"type": "filter", "expr": "datum.year == 2000"}, { "type": "aggregate", "groupby": ["age"], "ops": ["sum"], "fields": ["people"], "as": ["sum_people"] }, { "type": "filter", "expr": "isValid(datum[\"sum_people\"]) && isFinite(+datum[\"sum_people\"])" } ] } ], "signals": [ {"name": "y_step", "value": 17}, { "name": "height", "update": "bandspace(domain('y').length, 0.1, 0.05) * y_step" } ], "marks": [ { "name": "marks", "type": "rect", "style": ["bar"], "from": {"data": "source_0"}, "encode": { "update": { "fill": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"population: \" + (format(datum[\"sum_people\"], \"\")) + \"; age: \" + (isValid(datum[\"age\"]) ? datum[\"age\"] : \"\"+datum[\"age\"])" }, "x": {"scale": "x", "field": "sum_people"}, "x2": {"scale": "x", "value": 0}, "y": {"scale": "y", "field": "age"}, "height": {"scale": "y", "band": 1} } } } ], "scales": [ { "name": "x", "type": "linear", "domain": {"data": "source_0", "field": "sum_people"}, "range": [0, {"signal": "width"}], "nice": true, "zero": true }, { "name": "y", "type": "band", "domain": {"data": "source_0", "field": "age", "sort": true}, "range": {"step": {"signal": "y_step"}}, "paddingInner": 0.1, "paddingOuter": 0.05 } ], "axes": [ { "scale": "x", "orient": "bottom", "gridScale": "y", "grid": true, "tickCount": {"signal": "ceil(width/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 }, { "scale": "x", "orient": "bottom", "grid": false, "title": "population", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(width/40)"}, "zindex": 0 }, {"scale": "y", "orient": "left", "grid": false, "title": "age", "zindex": 0} ] }