{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "data": [ { "name": "source_0", "url": "https://raw.githubusercontent.com/vega/vega-datasets/master/data/barley.json", "format": {"type": "json"}, "transform": [ { "type": "aggregate", "groupby": ["variety", "site", "year"], "ops": ["sum"], "fields": ["yield"], "as": ["sum_yield"] }, { "type": "stack", "groupby": ["variety", "year"], "field": "sum_yield", "sort": {"field": ["site"], "order": ["ascending"]}, "as": ["sum_yield_start", "sum_yield_end"], "offset": "zero" }, { "type": "filter", "expr": "isValid(datum[\"sum_yield\"]) && isFinite(+datum[\"sum_yield\"])" } ] }, { "name": "column_domain", "source": "source_0", "transform": [{"type": "aggregate", "groupby": ["year"]}] } ], "signals": [ {"name": "child_width", "value": 200}, {"name": "y_step", "value": 20}, { "name": "child_height", "update": "bandspace(domain('y').length, 0.1, 0.05) * y_step" } ], "layout": { "padding": 20, "offset": {"columnTitle": 10}, "columns": {"signal": "length(data('column_domain'))"}, "bounds": "full", "align": "all" }, "marks": [ { "name": "column-title", "type": "group", "role": "column-title", "title": {"text": "year", "style": "guide-title", "offset": 10} }, { "name": "row_header", "type": "group", "role": "row-header", "encode": {"update": {"height": {"signal": "child_height"}}}, "axes": [ { "scale": "y", "orient": "left", "grid": false, "title": "variety", "zindex": 0 } ] }, { "name": "column_header", "type": "group", "role": "column-header", "from": {"data": "column_domain"}, "sort": {"field": "datum[\"year\"]", "order": "ascending"}, "title": { "text": { "signal": "isValid(parent[\"year\"]) ? parent[\"year\"] : \"\"+parent[\"year\"]" }, "style": "guide-label", "frame": "group", "offset": 10 }, "encode": {"update": {"width": {"signal": "child_width"}}} }, { "name": "column_footer", "type": "group", "role": "column-footer", "from": {"data": "column_domain"}, "sort": {"field": "datum[\"year\"]", "order": "ascending"}, "encode": {"update": {"width": {"signal": "child_width"}}}, "axes": [ { "scale": "x", "orient": "bottom", "grid": false, "title": "Sum of yield", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(child_width/40)"}, "zindex": 0 } ] }, { "name": "cell", "type": "group", "style": "cell", "from": { "facet": {"name": "facet", "data": "source_0", "groupby": ["year"]} }, "sort": {"field": ["datum[\"year\"]"], "order": ["ascending"]}, "encode": { "update": { "width": {"signal": "child_width"}, "height": {"signal": "child_height"} } }, "marks": [ { "name": "child_marks", "type": "rect", "style": ["bar"], "from": {"data": "facet"}, "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\"])" }, "x": {"scale": "x", "field": "sum_yield_end"}, "x2": {"scale": "x", "field": "sum_yield_start"}, "y": {"scale": "y", "field": "variety"}, "height": {"scale": "y", "band": 1} } } } ], "axes": [ { "scale": "x", "orient": "bottom", "gridScale": "y", "grid": true, "tickCount": {"signal": "ceil(child_width/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 } ] } ], "scales": [ { "name": "x", "type": "linear", "domain": { "data": "source_0", "fields": ["sum_yield_start", "sum_yield_end"] }, "range": [0, {"signal": "child_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" } ], "legends": [{"fill": "color", "symbolType": "square", "title": "site"}] }