Module

x/vega_lite/examples/compiled/bar_aggregate_sort_mean.vg.json

A concise grammar of interactive graphics, built on Vega.
Latest
File
{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "A bar chart that sorts the y-values by the x-values.", "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"}] }, { "name": "data_0", "source": "source_0", "transform": [ { "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": 20}, { "name": "height", "update": "bandspace(domain('y').length, 0.1, 0.05) * y_step" } ], "marks": [ { "name": "marks", "type": "rect", "style": ["bar"], "from": {"data": "data_0"}, "encode": { "update": { "fill": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"age: \" + (isValid(datum[\"age\"]) ? datum[\"age\"] : \"\"+datum[\"age\"]) + \"; population: \" + (format(datum[\"sum_people\"], \"\"))" }, "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": "data_0", "field": "sum_people"}, "range": [0, {"signal": "width"}], "nice": true, "zero": true }, { "name": "y", "type": "band", "domain": { "data": "source_0", "field": "age", "sort": {"op": "sum", "field": "people"} }, "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} ]}