{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "A horizontal box plot showing median, min, and max body mass of penguins.", "background": "white", "padding": 5, "width": 200, "style": "cell", "data": [ { "name": "source_0", "url": "data/penguins.json", "format": {"type": "json"}, "transform": [ { "type": "aggregate", "groupby": ["Species"], "ops": ["q1", "q3", "median", "min", "max"], "fields": [ "Body Mass (g)", "Body Mass (g)", "Body Mass (g)", "Body Mass (g)", "Body Mass (g)" ], "as": [ "lower_box_Body Mass (g)", "upper_box_Body Mass (g)", "mid_box_Body Mass (g)", "lower_whisker_Body Mass (g)", "upper_whisker_Body Mass (g)" ] } ] } ], "signals": [ {"name": "y_step", "value": 20}, {"name": "height", "update": "bandspace(domain('y').length, 0, 0) * y_step"} ], "marks": [ { "name": "layer_0_marks", "type": "rule", "style": ["rule", "boxplot-rule"], "aria": false, "from": {"data": "source_0"}, "encode": { "update": { "stroke": {"value": "black"}, "tooltip": { "signal": "{\"Max of Body Mass (g)\": format(datum[\"upper_whisker_Body Mass (g)\"], \"\"), \"Q3 of Body Mass (g)\": format(datum[\"upper_box_Body Mass (g)\"], \"\"), \"Median of Body Mass (g)\": format(datum[\"mid_box_Body Mass (g)\"], \"\"), \"Q1 of Body Mass (g)\": format(datum[\"lower_box_Body Mass (g)\"], \"\"), \"Min of Body Mass (g)\": format(datum[\"lower_whisker_Body Mass (g)\"], \"\"), \"Species\": isValid(datum[\"Species\"]) ? datum[\"Species\"] : \"\"+datum[\"Species\"]}" }, "x": [ { "test": "!isValid(datum[\"lower_whisker_Body Mass (g)\"]) || !isFinite(+datum[\"lower_whisker_Body Mass (g)\"])", "value": 0 }, {"scale": "x", "field": "lower_whisker_Body Mass (g)"} ], "x2": [ { "test": "!isValid(datum[\"lower_box_Body Mass (g)\"]) || !isFinite(+datum[\"lower_box_Body Mass (g)\"])", "value": 0 }, {"scale": "x", "field": "lower_box_Body Mass (g)"} ], "y": {"scale": "y", "field": "Species", "band": 0.5} } } }, { "name": "layer_1_marks", "type": "rule", "style": ["rule", "boxplot-rule"], "aria": false, "from": {"data": "source_0"}, "encode": { "update": { "stroke": {"value": "black"}, "tooltip": { "signal": "{\"Max of Body Mass (g)\": format(datum[\"upper_whisker_Body Mass (g)\"], \"\"), \"Q3 of Body Mass (g)\": format(datum[\"upper_box_Body Mass (g)\"], \"\"), \"Median of Body Mass (g)\": format(datum[\"mid_box_Body Mass (g)\"], \"\"), \"Q1 of Body Mass (g)\": format(datum[\"lower_box_Body Mass (g)\"], \"\"), \"Min of Body Mass (g)\": format(datum[\"lower_whisker_Body Mass (g)\"], \"\"), \"Species\": isValid(datum[\"Species\"]) ? datum[\"Species\"] : \"\"+datum[\"Species\"]}" }, "x": [ { "test": "!isValid(datum[\"upper_box_Body Mass (g)\"]) || !isFinite(+datum[\"upper_box_Body Mass (g)\"])", "value": 0 }, {"scale": "x", "field": "upper_box_Body Mass (g)"} ], "x2": [ { "test": "!isValid(datum[\"upper_whisker_Body Mass (g)\"]) || !isFinite(+datum[\"upper_whisker_Body Mass (g)\"])", "value": 0 }, {"scale": "x", "field": "upper_whisker_Body Mass (g)"} ], "y": {"scale": "y", "field": "Species", "band": 0.5} } } }, { "name": "layer_2_marks", "type": "rect", "style": ["bar", "boxplot-box"], "from": {"data": "source_0"}, "encode": { "update": { "ariaRoleDescription": {"value": "box"}, "fill": {"value": "#4c78a8"}, "tooltip": { "signal": "{\"Max of Body Mass (g)\": format(datum[\"upper_whisker_Body Mass (g)\"], \"\"), \"Q3 of Body Mass (g)\": format(datum[\"upper_box_Body Mass (g)\"], \"\"), \"Median of Body Mass (g)\": format(datum[\"mid_box_Body Mass (g)\"], \"\"), \"Q1 of Body Mass (g)\": format(datum[\"lower_box_Body Mass (g)\"], \"\"), \"Min of Body Mass (g)\": format(datum[\"lower_whisker_Body Mass (g)\"], \"\"), \"Species\": isValid(datum[\"Species\"]) ? datum[\"Species\"] : \"\"+datum[\"Species\"]}" }, "description": { "signal": "\"Body Mass (g): \" + (format(datum[\"lower_box_Body Mass (g)\"], \"\")) + \"; Species: \" + (isValid(datum[\"Species\"]) ? datum[\"Species\"] : \"\"+datum[\"Species\"]) + \"; upper_box_Body Mass (g): \" + (format(datum[\"upper_box_Body Mass (g)\"], \"\")) + \"; Max of Body Mass (g): \" + (format(datum[\"upper_whisker_Body Mass (g)\"], \"\")) + \"; Q3 of Body Mass (g): \" + (format(datum[\"upper_box_Body Mass (g)\"], \"\")) + \"; Median of Body Mass (g): \" + (format(datum[\"mid_box_Body Mass (g)\"], \"\")) + \"; Q1 of Body Mass (g): \" + (format(datum[\"lower_box_Body Mass (g)\"], \"\")) + \"; Min of Body Mass (g): \" + (format(datum[\"lower_whisker_Body Mass (g)\"], \"\"))" }, "x": [ { "test": "!isValid(datum[\"lower_box_Body Mass (g)\"]) || !isFinite(+datum[\"lower_box_Body Mass (g)\"])", "value": 0 }, {"scale": "x", "field": "lower_box_Body Mass (g)"} ], "x2": [ { "test": "!isValid(datum[\"upper_box_Body Mass (g)\"]) || !isFinite(+datum[\"upper_box_Body Mass (g)\"])", "value": 0 }, {"scale": "x", "field": "upper_box_Body Mass (g)"} ], "yc": {"scale": "y", "field": "Species", "band": 0.5}, "height": {"value": 14} } } }, { "name": "layer_3_marks", "type": "rect", "style": ["tick", "boxplot-median"], "aria": false, "from": {"data": "source_0"}, "encode": { "update": { "opacity": {"value": 0.7}, "fill": {"value": "white"}, "tooltip": { "signal": "{\"Max of Body Mass (g)\": format(datum[\"upper_whisker_Body Mass (g)\"], \"\"), \"Q3 of Body Mass (g)\": format(datum[\"upper_box_Body Mass (g)\"], \"\"), \"Median of Body Mass (g)\": format(datum[\"mid_box_Body Mass (g)\"], \"\"), \"Q1 of Body Mass (g)\": format(datum[\"lower_box_Body Mass (g)\"], \"\"), \"Min of Body Mass (g)\": format(datum[\"lower_whisker_Body Mass (g)\"], \"\"), \"Species\": isValid(datum[\"Species\"]) ? datum[\"Species\"] : \"\"+datum[\"Species\"]}" }, "xc": [ { "test": "!isValid(datum[\"mid_box_Body Mass (g)\"]) || !isFinite(+datum[\"mid_box_Body Mass (g)\"])", "value": 0 }, {"scale": "x", "field": "mid_box_Body Mass (g)"} ], "yc": {"scale": "y", "field": "Species", "band": 0.5}, "height": {"value": 14}, "width": {"value": 1} } } } ], "scales": [ { "name": "x", "type": "linear", "domain": { "data": "source_0", "fields": [ "lower_whisker_Body Mass (g)", "lower_box_Body Mass (g)", "upper_box_Body Mass (g)", "upper_whisker_Body Mass (g)", "mid_box_Body Mass (g)" ] }, "range": [0, {"signal": "width"}], "zero": false, "nice": true }, { "name": "y", "type": "band", "domain": {"data": "source_0", "field": "Species", "sort": true}, "range": {"step": {"signal": "y_step"}}, "paddingInner": 0, "paddingOuter": 0 } ], "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": "Body Mass (g)", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(width/40)"}, "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "Species", "zindex": 0 } ] }