{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "height": 200, "style": "cell", "data": [ { "name": "source_0", "values": [ {"category": "A", "group": "x", "value": 0.1}, {"category": "A", "group": "y", "value": 0.6}, {"category": "A", "group": "z", "value": 0.9}, {"category": "B", "group": "x", "value": 0.7}, {"category": "B", "group": "y", "value": 0.2}, {"category": "B", "group": "z", "value": 1.1}, {"category": "C", "group": "x", "value": 0.6}, {"category": "C", "group": "y", "value": 0.1}, {"category": "C", "group": "z", "value": 0.2} ] }, { "name": "data_1", "source": "source_0", "transform": [ { "type": "stack", "groupby": ["category", "group"], "field": "value", "sort": {"field": [], "order": []}, "as": ["value_start", "value_end"], "offset": "zero" }, { "type": "filter", "expr": "isValid(datum[\"value\"]) && isFinite(+datum[\"value\"])" } ] }, { "name": "data_2", "source": "source_0", "transform": [ { "type": "aggregate", "groupby": ["category"], "ops": ["mean"], "fields": ["value"], "as": ["mean_value"] } ] } ], "signals": [ { "name": "x_step", "update": "20 * bandspace(domain('xOffset').length, 0, 0) / (1-0.2)" }, { "name": "width", "update": "bandspace(domain('x').length, 0.2, 0.2) * x_step" } ], "marks": [ { "name": "layer_0_marks", "type": "rect", "style": ["bar"], "from": {"data": "data_1"}, "encode": { "update": { "fill": {"scale": "color", "field": "group"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"category: \" + (isValid(datum[\"category\"]) ? datum[\"category\"] : \"\"+datum[\"category\"]) + \"; value: \" + (format(datum[\"value\"], \"\")) + \"; group: \" + (isValid(datum[\"group\"]) ? datum[\"group\"] : \"\"+datum[\"group\"])" }, "x": { "scale": "x", "field": "category", "offset": {"scale": "xOffset", "field": "group"} }, "width": {"scale": "xOffset", "band": 1}, "y": {"scale": "y", "field": "value_end"}, "y2": {"scale": "y", "field": "value_start"} } } }, { "name": "layer_1_marks", "type": "line", "style": ["line"], "sort": {"field": "datum[\"category\"]"}, "from": {"data": "data_2"}, "encode": { "update": { "stroke": {"value": "black"}, "description": { "signal": "\"category: \" + (isValid(datum[\"category\"]) ? datum[\"category\"] : \"\"+datum[\"category\"]) + \"; Mean of value: \" + (format(datum[\"mean_value\"], \"\"))" }, "x": {"scale": "x", "field": "category", "band": 0.5}, "y": {"scale": "y", "field": "mean_value"}, "defined": { "signal": "isValid(datum[\"mean_value\"]) && isFinite(+datum[\"mean_value\"])" } } } } ], "scales": [ { "name": "x", "type": "band", "domain": { "fields": [ {"data": "data_1", "field": "category"}, {"data": "data_2", "field": "category"} ], "sort": true }, "range": {"step": {"signal": "x_step"}}, "paddingInner": 0.2, "paddingOuter": 0.2 }, { "name": "y", "type": "linear", "domain": { "fields": [ {"data": "data_1", "field": "value_start"}, {"data": "data_1", "field": "value_end"}, {"data": "data_2", "field": "mean_value"} ] }, "range": [{"signal": "height"}, 0], "nice": true, "zero": true }, { "name": "xOffset", "type": "band", "domain": {"data": "data_1", "field": "group", "sort": true}, "range": {"step": 20} }, { "name": "color", "type": "ordinal", "domain": {"data": "data_1", "field": "group", "sort": true}, "range": "category" } ], "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": "category", "labelAlign": "right", "labelAngle": 270, "labelBaseline": "middle", "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "value, Mean of value", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ], "legends": [{"fill": "color", "symbolType": "square", "title": "group"}] }