{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "title": {"text": "Distribution of Body Mass of Penguins", "anchor": "start"}, "data": [ { "name": "source_0", "url": "data/penguins.json", "format": {"type": "json"}, "transform": [ { "type": "kde", "field": "Body Mass (g)", "groupby": ["Species"], "extent": [2500, 6500], "as": ["value", "density"] }, { "type": "impute", "field": "density", "groupby": ["Species"], "key": "value", "method": "value", "value": 0 }, { "type": "stack", "groupby": ["value", "Species"], "field": "density", "sort": {"field": [], "order": []}, "as": ["density_start", "density_end"], "offset": "zero" } ] }, { "name": "row_domain", "source": "source_0", "transform": [{"type": "aggregate", "groupby": ["Species"]}] } ], "signals": [ {"name": "child_width", "value": 400}, {"name": "child_height", "value": 80} ], "layout": { "padding": 20, "offset": {"rowTitle": 10}, "columns": 1, "bounds": "full", "align": "all" }, "marks": [ { "name": "row-title", "type": "group", "role": "row-title", "title": { "text": "Species", "orient": "left", "style": "guide-title", "offset": 10 } }, { "name": "row_header", "type": "group", "role": "row-header", "from": {"data": "row_domain"}, "sort": {"field": "datum[\"Species\"]", "order": "ascending"}, "title": { "text": { "signal": "isValid(parent[\"Species\"]) ? parent[\"Species\"] : \"\"+parent[\"Species\"]" }, "orient": "left", "style": "guide-label", "frame": "group", "offset": 10 }, "encode": {"update": {"height": {"signal": "child_height"}}}, "axes": [ { "scale": "y", "orient": "left", "grid": false, "title": "density", "labelOverlap": true, "tickCount": {"signal": "ceil(child_height/40)"}, "zindex": 0 } ] }, { "name": "column_footer", "type": "group", "role": "column-footer", "encode": {"update": {"width": {"signal": "child_width"}}}, "axes": [ { "scale": "x", "orient": "bottom", "grid": false, "title": "Body Mass (g)", "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": ["Species"]} }, "sort": {"field": ["datum[\"Species\"]"], "order": ["ascending"]}, "encode": { "update": { "width": {"signal": "child_width"}, "height": {"signal": "child_height"} } }, "marks": [ { "name": "child_marks", "type": "area", "style": ["area"], "sort": {"field": "datum[\"value\"]"}, "from": {"data": "facet"}, "encode": { "update": { "orient": {"value": "vertical"}, "fill": {"value": "#4c78a8"}, "description": { "signal": "\"Body Mass (g): \" + (format(datum[\"value\"], \"\")) + \"; density: \" + (format(datum[\"density\"], \"\"))" }, "x": {"scale": "x", "field": "value"}, "y": {"scale": "y", "field": "density_end"}, "y2": {"scale": "y", "field": "density_start"}, "defined": { "signal": "isValid(datum[\"value\"]) && isFinite(+datum[\"value\"]) && isValid(datum[\"density\"]) && isFinite(+datum[\"density\"])" } } } } ], "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 }, { "scale": "y", "orient": "left", "gridScale": "x", "grid": true, "tickCount": {"signal": "ceil(child_height/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 } ] } ], "scales": [ { "name": "x", "type": "linear", "domain": {"data": "source_0", "field": "value"}, "range": [0, {"signal": "child_width"}], "nice": true, "zero": false }, { "name": "y", "type": "linear", "domain": { "data": "source_0", "fields": ["density_start", "density_end"] }, "range": [{"signal": "child_height"}, 0], "nice": true, "zero": true } ] }