{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "style": "cell", "data": [ { "name": "source_0", "url": "data/cars.json", "format": {"type": "json"}, "transform": [ { "type": "aggregate", "groupby": ["Cylinders", "Origin"], "ops": ["mean"], "fields": ["Horsepower"], "as": ["mean_Horsepower"] }, { "type": "filter", "expr": "isValid(datum[\"mean_Horsepower\"]) && isFinite(+datum[\"mean_Horsepower\"])" } ] } ], "signals": [ {"name": "x_step", "value": 20}, {"name": "width", "update": "bandspace(domain('x').length, 0, 0) * x_step"}, {"name": "y_step", "value": 20}, {"name": "height", "update": "bandspace(domain('y').length, 0, 0) * y_step"} ], "marks": [ { "name": "marks", "type": "rect", "style": ["rect"], "from": {"data": "source_0"}, "encode": { "update": { "fill": {"scale": "color", "field": "mean_Horsepower"}, "description": { "signal": "\"Cylinders: \" + (isValid(datum[\"Cylinders\"]) ? datum[\"Cylinders\"] : \"\"+datum[\"Cylinders\"]) + \"; Origin: \" + (isValid(datum[\"Origin\"]) ? datum[\"Origin\"] : \"\"+datum[\"Origin\"]) + \"; Mean of Horsepower: \" + (format(datum[\"mean_Horsepower\"], \"\"))" }, "x": {"scale": "x", "field": "Cylinders"}, "width": {"scale": "x", "band": 1}, "y": {"scale": "y", "field": "Origin"}, "height": {"scale": "y", "band": 1} } } } ], "scales": [ { "name": "x", "type": "band", "domain": {"data": "source_0", "field": "Cylinders", "sort": true}, "range": {"step": {"signal": "x_step"}}, "paddingInner": 0, "paddingOuter": 0 }, { "name": "y", "type": "band", "domain": {"data": "source_0", "field": "Origin", "sort": true}, "range": {"step": {"signal": "y_step"}}, "paddingInner": 0, "paddingOuter": 0 }, { "name": "color", "type": "linear", "domain": {"data": "source_0", "field": "mean_Horsepower"}, "range": "heatmap", "interpolate": "hcl", "zero": false } ], "axes": [ { "scale": "x", "orient": "bottom", "gridScale": "y", "grid": true, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 1 }, { "scale": "y", "orient": "left", "gridScale": "x", "grid": true, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 1 }, { "scale": "x", "orient": "bottom", "grid": false, "title": "Cylinders", "labelAlign": "right", "labelAngle": 270, "labelBaseline": "middle", "zindex": 1 }, { "scale": "y", "orient": "left", "grid": false, "title": "Origin", "zindex": 1 } ], "legends": [ { "fill": "color", "gradientLength": {"signal": "clamp(height, 64, 200)"}, "title": "Mean of Horsepower" } ], "config": {"axis": {"grid": true, "tickBand": "extent"}} }