{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "Relative frequency histogram. The data is binned with first transform. The number of values per bin and the total number are calculated in the second and third transform to calculate the relative frequency in the last transformation step.", "background": "white", "padding": 5, "width": 200, "height": 200, "style": "cell", "data": [ { "name": "source_0", "url": "data/cars.json", "format": {"type": "json"}, "transform": [ { "type": "extent", "field": "Horsepower", "signal": "bin_maxbins_10_Horsepower_extent" }, { "type": "bin", "field": "Horsepower", "as": ["bin_Horsepwoer", "bin_Horsepwoer_end"], "signal": "bin_maxbins_10_Horsepower_bins", "extent": {"signal": "bin_maxbins_10_Horsepower_extent"}, "maxbins": 10 }, { "type": "aggregate", "groupby": ["bin_Horsepwoer", "bin_Horsepwoer_end"], "ops": ["count"], "fields": [null], "as": ["Count"] }, { "type": "joinaggregate", "as": ["TotalCount"], "ops": ["sum"], "fields": ["Count"] }, { "type": "formula", "expr": "datum.Count/datum.TotalCount", "as": "PercentOfTotal" }, { "type": "stack", "groupby": ["bin_Horsepwoer", "bin_Horsepwoer"], "field": "PercentOfTotal", "sort": {"field": [], "order": []}, "as": ["PercentOfTotal_start", "PercentOfTotal_end"], "offset": "zero" }, { "type": "filter", "expr": "isValid(datum[\"bin_Horsepwoer\"]) && isFinite(+datum[\"bin_Horsepwoer\"]) && isValid(datum[\"PercentOfTotal\"]) && isFinite(+datum[\"PercentOfTotal\"])" } ] } ], "marks": [ { "name": "marks", "type": "rect", "style": ["bar"], "from": {"data": "source_0"}, "encode": { "update": { "tooltip": { "signal": "{\"Horsepower\": !isValid(datum[\"bin_Horsepwoer\"]) || !isFinite(+datum[\"bin_Horsepwoer\"]) ? \"null\" : format(datum[\"bin_Horsepwoer\"], \"\") + \" – \" + format(datum[\"bin_Horsepwoer_end\"], \"\"), \"Relative Frequency\": format(datum[\"PercentOfTotal\"], \".1~%\")}" }, "fill": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"Horsepower: \" + (!isValid(datum[\"bin_Horsepwoer\"]) || !isFinite(+datum[\"bin_Horsepwoer\"]) ? \"null\" : format(datum[\"bin_Horsepwoer\"], \"\") + \" – \" + format(datum[\"bin_Horsepwoer_end\"], \"\")) + \"; Relative Frequency: \" + (format(datum[\"PercentOfTotal\"], \".1~%\"))" }, "x2": {"scale": "x", "field": "bin_Horsepwoer", "offset": 1}, "x": {"scale": "x", "field": "bin_Horsepwoer_end"}, "y": {"scale": "y", "field": "PercentOfTotal_end"}, "y2": {"scale": "y", "field": "PercentOfTotal_start"} } } } ], "scales": [ { "name": "x", "type": "linear", "domain": { "data": "source_0", "fields": ["bin_Horsepwoer", "bin_Horsepwoer_end"] }, "range": [0, {"signal": "width"}], "zero": false }, { "name": "y", "type": "linear", "domain": { "data": "source_0", "fields": ["PercentOfTotal_start", "PercentOfTotal_end"] }, "range": [{"signal": "height"}, 0], "nice": true, "zero": true } ], "axes": [ { "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": "Horsepower", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(width/40)"}, "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "Relative Frequency", "format": ".1~%", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ] }