{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "width": 400, "height": 100, "style": "cell", "data": [ { "name": "source_0", "url": "data/cars.json", "format": {"type": "json"}, "transform": [ { "type": "fold", "fields": ["Displacement", "Horsepower"], "as": ["Measurement", "value"] }, { "type": "kde", "field": "value", "bandwidth": 10, "groupby": ["Measurement"], "extent": [10, 500], "counts": true, "steps": 200, "as": ["value", "density"] }, { "type": "impute", "field": "density", "groupby": ["Measurement"], "key": "value", "method": "value", "value": 0 }, { "type": "stack", "groupby": ["value"], "field": "density", "sort": {"field": ["Measurement"], "order": ["descending"]}, "as": ["density_start", "density_end"], "offset": "zero" } ] } ], "marks": [ { "name": "pathgroup", "type": "group", "from": { "facet": { "name": "faceted_path_main", "data": "source_0", "groupby": ["Measurement"] } }, "encode": { "update": { "width": {"field": {"group": "width"}}, "height": {"field": {"group": "height"}} } }, "marks": [ { "name": "marks", "type": "area", "style": ["area"], "sort": {"field": "datum[\"value\"]"}, "from": {"data": "faceted_path_main"}, "encode": { "update": { "orient": {"value": "vertical"}, "fill": {"scale": "color", "field": "Measurement"}, "description": { "signal": "\"value: \" + (format(datum[\"value\"], \"\")) + \"; density: \" + (format(datum[\"density\"], \"\")) + \"; Measurement: \" + (isValid(datum[\"Measurement\"]) ? datum[\"Measurement\"] : \"\"+datum[\"Measurement\"])" }, "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\"])" } } } } ] } ], "scales": [ { "name": "x", "type": "linear", "domain": {"data": "source_0", "field": "value"}, "range": [0, {"signal": "width"}], "nice": true, "zero": false }, { "name": "y", "type": "linear", "domain": { "data": "source_0", "fields": ["density_start", "density_end"] }, "range": [{"signal": "height"}, 0], "nice": true, "zero": true }, { "name": "color", "type": "ordinal", "domain": {"data": "source_0", "field": "Measurement", "sort": true}, "range": "category" } ], "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": "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": "value", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(width/40)"}, "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "density", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ], "legends": [{"fill": "color", "symbolType": "circle", "title": "Measurement"}] }