{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "A vertical box plot showing median, min, and max body mass of penguins.", "background": "white", "padding": 5, "height": 200, "style": "cell", "data": [ { "name": "source_0", "url": "data/cars.json", "format": {"type": "json"}, "transform": [ { "type": "aggregate", "groupby": ["Cylinders", "Origin"], "ops": ["stderr", "mean", "mean"], "fields": ["Acceleration", "Acceleration", "Acceleration"], "as": [ "extent_Acceleration", "center_Acceleration", "mean_Acceleration" ] } ] }, { "name": "data_0", "source": "source_0", "transform": [ { "type": "formula", "expr": "datum[\"center_Acceleration\"] + datum[\"extent_Acceleration\"]", "as": "upper_Acceleration" }, { "type": "formula", "expr": "datum[\"center_Acceleration\"] - datum[\"extent_Acceleration\"]", "as": "lower_Acceleration" }, { "type": "filter", "expr": "isValid(datum[\"lower_Acceleration\"]) && isFinite(+datum[\"lower_Acceleration\"])" } ] }, { "name": "data_1", "source": "source_0", "transform": [ { "type": "filter", "expr": "isValid(datum[\"mean_Acceleration\"]) && isFinite(+datum[\"mean_Acceleration\"])" } ] } ], "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": "Origin"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"Cylinders: \" + (isValid(datum[\"Cylinders\"]) ? datum[\"Cylinders\"] : \"\"+datum[\"Cylinders\"]) + \"; Mean of Acceleration: \" + (format(datum[\"mean_Acceleration\"], \"\")) + \"; Origin: \" + (isValid(datum[\"Origin\"]) ? datum[\"Origin\"] : \"\"+datum[\"Origin\"])" }, "x": { "scale": "x", "field": "Cylinders", "offset": {"scale": "xOffset", "field": "Origin"} }, "width": {"scale": "xOffset", "band": 1}, "y": {"scale": "y", "field": "mean_Acceleration"}, "y2": {"scale": "y", "value": 0} } } }, { "name": "layer_1_marks", "type": "rule", "style": ["rule", "errorbar-rule"], "from": {"data": "data_0"}, "encode": { "update": { "ariaRoleDescription": {"value": "errorbar"}, "stroke": {"value": "black"}, "tooltip": { "signal": "{\"Mean of Acceleration\": format(datum[\"center_Acceleration\"], \"\"), \"Mean + stderr of Acceleration\": format(datum[\"upper_Acceleration\"], \"\"), \"Mean - stderr of Acceleration\": format(datum[\"lower_Acceleration\"], \"\"), \"Cylinders\": isValid(datum[\"Cylinders\"]) ? datum[\"Cylinders\"] : \"\"+datum[\"Cylinders\"], \"Origin\": isValid(datum[\"Origin\"]) ? datum[\"Origin\"] : \"\"+datum[\"Origin\"]}" }, "description": { "signal": "\"Cylinders: \" + (isValid(datum[\"Cylinders\"]) ? datum[\"Cylinders\"] : \"\"+datum[\"Cylinders\"]) + \"; Acceleration: \" + (format(datum[\"lower_Acceleration\"], \"\")) + \"; upper_Acceleration: \" + (format(datum[\"upper_Acceleration\"], \"\")) + \"; Origin: \" + (isValid(datum[\"Origin\"]) ? datum[\"Origin\"] : \"\"+datum[\"Origin\"]) + \"; Mean of Acceleration: \" + (format(datum[\"center_Acceleration\"], \"\")) + \"; Mean + stderr of Acceleration: \" + (format(datum[\"upper_Acceleration\"], \"\")) + \"; Mean - stderr of Acceleration: \" + (format(datum[\"lower_Acceleration\"], \"\"))" }, "x": { "scale": "x", "field": "Cylinders", "offset": {"scale": "xOffset", "field": "Origin", "band": 0.5} }, "y": {"scale": "y", "field": "lower_Acceleration"}, "y2": {"scale": "y", "field": "upper_Acceleration"} } } } ], "scales": [ { "name": "x", "type": "band", "domain": { "fields": [ {"data": "data_1", "field": "Cylinders"}, {"data": "data_0", "field": "Cylinders"} ], "sort": true }, "range": {"step": {"signal": "x_step"}}, "paddingInner": 0.2, "paddingOuter": 0.2 }, { "name": "y", "type": "linear", "domain": { "fields": [ {"data": "data_1", "field": "mean_Acceleration"}, {"data": "data_0", "field": "lower_Acceleration"}, {"data": "data_0", "field": "upper_Acceleration"} ] }, "range": [{"signal": "height"}, 0], "nice": true, "zero": true }, { "name": "xOffset", "type": "band", "domain": { "fields": [ {"data": "data_1", "field": "Origin"}, {"data": "data_0", "field": "Origin"} ], "sort": true }, "range": {"step": 20} }, { "name": "color", "type": "ordinal", "domain": {"data": "data_1", "field": "Origin", "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": "Cylinders", "labelAlign": "right", "labelAngle": 270, "labelBaseline": "middle", "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "Acceleration", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ], "legends": [{"fill": "color", "symbolType": "square", "title": "Origin"}] }