{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "width": 200, "height": 200, "style": "cell", "data": [ { "name": "source_0", "url": "data/cars.json", "format": {"type": "json"}, "transform": [ { "type": "aggregate", "groupby": ["Origin", "Cylinders"], "ops": ["count"], "fields": [null], "as": ["count_*"] }, { "type": "stack", "groupby": [], "field": "count_*", "sort": {"field": ["Origin"], "order": ["ascending"]}, "as": ["stack_count_Origin1", "stack_count_Origin2"], "offset": "normalize" }, { "type": "joinaggregate", "as": ["x", "x2"], "ops": ["min", "max"], "fields": ["stack_count_Origin1", "stack_count_Origin2"], "groupby": ["Origin"] }, { "type": "stack", "groupby": ["Origin"], "field": "count_*", "sort": {"field": ["Cylinders"], "order": ["ascending"]}, "as": ["y", "y2"], "offset": "normalize" }, { "type": "filter", "expr": "isValid(datum[\"x\"]) && isFinite(+datum[\"x\"]) && isValid(datum[\"y\"]) && isFinite(+datum[\"y\"]) && isValid(datum[\"Cylinders\"]) && isFinite(+datum[\"Cylinders\"])" } ] } ], "marks": [ { "name": "marks", "type": "rect", "style": ["rect"], "from": {"data": "source_0"}, "encode": { "update": { "fill": {"scale": "color", "field": "Origin"}, "opacity": {"scale": "opacity", "field": "Cylinders"}, "tooltip": { "signal": "{\"Origin\": isValid(datum[\"Origin\"]) ? datum[\"Origin\"] : \"\"+datum[\"Origin\"], \"Cylinders\": format(datum[\"Cylinders\"], \"\")}" }, "description": { "signal": "\"x: \" + (format(datum[\"x\"], \"\")) + \"; y: \" + (format(datum[\"y\"], \"\")) + \"; x2: \" + (format(datum[\"x2\"], \"\")) + \"; y2: \" + (format(datum[\"y2\"], \"\")) + \"; Origin: \" + (isValid(datum[\"Origin\"]) ? datum[\"Origin\"] : \"\"+datum[\"Origin\"]) + \"; Cylinders: \" + (format(datum[\"Cylinders\"], \"\"))" }, "x": {"scale": "x", "field": "x"}, "x2": {"scale": "x", "field": "x2"}, "y": {"scale": "y", "field": "y"}, "y2": {"scale": "y", "field": "y2"} } } } ], "scales": [ { "name": "x", "type": "linear", "domain": {"data": "source_0", "fields": ["x", "x2"]}, "range": [0, {"signal": "width"}], "nice": true, "zero": true }, { "name": "y", "type": "linear", "domain": {"data": "source_0", "fields": ["y", "y2"]}, "range": [{"signal": "height"}, 0], "nice": true, "zero": true }, { "name": "color", "type": "ordinal", "domain": {"data": "source_0", "field": "Origin", "sort": true}, "range": "category" }, { "name": "opacity", "type": "linear", "domain": {"data": "source_0", "field": "Cylinders"}, "range": [0.3, 0.8], "zero": false } ], "legends": [{"fill": "color", "symbolType": "square", "title": "Origin"}] }