{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "width": 200, "style": "cell", "data": [ { "name": "source_0", "url": "data/barley.json", "format": {"type": "json"}, "transform": [ { "type": "formula", "expr": "if(datum.site === 'University Farm', 0, if(datum.site === 'Grand Rapids', 1, 2))", "as": "siteOrder" }, { "type": "aggregate", "groupby": ["variety", "site", "siteOrder"], "ops": ["sum"], "fields": ["yield"], "as": ["sum_yield"] }, { "type": "stack", "groupby": ["variety"], "field": "sum_yield", "sort": {"field": ["siteOrder"], "order": ["ascending"]}, "as": ["sum_yield_start", "sum_yield_end"], "offset": "zero" }, { "type": "filter", "expr": "isValid(datum[\"sum_yield\"]) && isFinite(+datum[\"sum_yield\"])" } ] } ], "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": "source_0"}, "encode": { "update": { "fill": {"scale": "color", "field": "site"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"Sum of yield: \" + (format(datum[\"sum_yield\"], \"\")) + \"; variety: \" + (isValid(datum[\"variety\"]) ? datum[\"variety\"] : \"\"+datum[\"variety\"]) + \"; site: \" + (isValid(datum[\"site\"]) ? datum[\"site\"] : \"\"+datum[\"site\"]) + \"; siteOrder: \" + (isValid(datum[\"siteOrder\"]) ? datum[\"siteOrder\"] : \"\"+datum[\"siteOrder\"])" }, "x": {"scale": "x", "field": "sum_yield_end"}, "x2": {"scale": "x", "field": "sum_yield_start"}, "y": {"scale": "y", "field": "variety"}, "height": {"scale": "y", "band": 1} } } } ], "scales": [ { "name": "x", "type": "linear", "domain": { "data": "source_0", "fields": ["sum_yield_start", "sum_yield_end"] }, "range": [0, {"signal": "width"}], "nice": true, "zero": true }, { "name": "y", "type": "band", "domain": {"data": "source_0", "field": "variety", "sort": true}, "range": {"step": {"signal": "y_step"}}, "paddingInner": 0.1, "paddingOuter": 0.05 }, { "name": "color", "type": "ordinal", "domain": {"data": "source_0", "field": "site", "sort": true}, "range": "category" } ], "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": "Sum of yield", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(width/40)"}, "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "variety", "zindex": 0 } ], "legends": [{"fill": "color", "symbolType": "square", "title": "site"}] }