Module

x/vega_lite/examples/compiled/layer_boxplot_circle.vg.json

A concise grammar of interactive graphics, built on Vega.
Latest
File
{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "A horizontal box plot showing median, min, and max in the US population distribution of age groups in 2000 and all raw data on the top.", "background": "white", "padding": 5, "width": 500, "style": "cell", "data": [ { "name": "source_0", "url": "data/population.json", "format": {"type": "json"} }, { "name": "data_0", "source": "source_0", "transform": [ { "type": "joinaggregate", "as": ["lower_box_people", "upper_box_people"], "ops": ["q1", "q3"], "fields": ["people", "people"], "groupby": ["age"] }, { "type": "filter", "expr": "(datum[\"lower_box_people\"] - 1.5 * (datum[\"upper_box_people\"] - datum[\"lower_box_people\"]) <= datum[\"people\"]) && (datum[\"people\"] <= datum[\"upper_box_people\"] + 1.5 * (datum[\"upper_box_people\"] - datum[\"lower_box_people\"]))" }, { "type": "aggregate", "groupby": ["age"], "ops": ["min", "max", "min", "max"], "fields": [ "people", "people", "lower_box_people", "upper_box_people" ], "as": [ "lower_whisker_people", "upper_whisker_people", "lower_box_people", "upper_box_people" ] } ] }, { "name": "data_1", "source": "source_0", "transform": [ { "type": "aggregate", "groupby": ["age"], "ops": ["q1", "q3", "median", "min", "max"], "fields": ["people", "people", "people", "people", "people"], "as": [ "lower_box_people", "upper_box_people", "mid_box_people", "min_people", "max_people" ] } ] }, { "name": "data_2", "source": "source_0", "transform": [ { "type": "filter", "expr": "isValid(datum[\"people\"]) && isFinite(+datum[\"people\"])" } ] } ], "signals": [ {"name": "y_step", "value": 20}, {"name": "height", "update": "bandspace(domain('y').length, 0, 0) * y_step"} ], "marks": [ { "name": "layer_0_layer_0_layer_0_marks", "type": "rule", "style": ["rule", "boxplot-rule"], "aria": false, "from": {"data": "data_0"}, "encode": { "update": { "stroke": {"value": "black"}, "tooltip": { "signal": "{\"Upper Whisker of population\": format(datum[\"upper_whisker_people\"], \"\"), \"Lower Whisker of population\": format(datum[\"lower_whisker_people\"], \"\"), \"age\": isValid(datum[\"age\"]) ? datum[\"age\"] : \"\"+datum[\"age\"]}" }, "x": {"scale": "x", "field": "lower_whisker_people"}, "x2": {"scale": "x", "field": "lower_box_people"}, "y": {"scale": "y", "field": "age", "band": 0.5} } } }, { "name": "layer_0_layer_0_layer_1_marks", "type": "rule", "style": ["rule", "boxplot-rule"], "aria": false, "from": {"data": "data_0"}, "encode": { "update": { "stroke": {"value": "black"}, "tooltip": { "signal": "{\"Upper Whisker of population\": format(datum[\"upper_whisker_people\"], \"\"), \"Lower Whisker of population\": format(datum[\"lower_whisker_people\"], \"\"), \"age\": isValid(datum[\"age\"]) ? datum[\"age\"] : \"\"+datum[\"age\"]}" }, "x": {"scale": "x", "field": "upper_box_people"}, "x2": {"scale": "x", "field": "upper_whisker_people"}, "y": {"scale": "y", "field": "age", "band": 0.5} } } }, { "name": "layer_0_layer_1_layer_0_marks", "type": "rect", "style": ["bar", "boxplot-box"], "from": {"data": "data_1"}, "encode": { "update": { "ariaRoleDescription": {"value": "box"}, "fill": {"value": "#4c78a8"}, "tooltip": { "signal": "{\"Max of population\": format(datum[\"max_people\"], \"\"), \"Q3 of population\": format(datum[\"upper_box_people\"], \"\"), \"Median of population\": format(datum[\"mid_box_people\"], \"\"), \"Q1 of population\": format(datum[\"lower_box_people\"], \"\"), \"Min of population\": format(datum[\"min_people\"], \"\"), \"age\": isValid(datum[\"age\"]) ? datum[\"age\"] : \"\"+datum[\"age\"]}" }, "description": { "signal": "\"population: \" + (format(datum[\"lower_box_people\"], \"\")) + \"; upper_box_people: \" + (format(datum[\"upper_box_people\"], \"\")) + \"; age: \" + (isValid(datum[\"age\"]) ? datum[\"age\"] : \"\"+datum[\"age\"]) + \"; Max of population: \" + (format(datum[\"max_people\"], \"\")) + \"; Q3 of population: \" + (format(datum[\"upper_box_people\"], \"\")) + \"; Median of population: \" + (format(datum[\"mid_box_people\"], \"\")) + \"; Q1 of population: \" + (format(datum[\"lower_box_people\"], \"\")) + \"; Min of population: \" + (format(datum[\"min_people\"], \"\"))" }, "x": {"scale": "x", "field": "lower_box_people"}, "x2": {"scale": "x", "field": "upper_box_people"}, "yc": {"scale": "y", "field": "age", "band": 0.5}, "height": {"value": 14} } } }, { "name": "layer_0_layer_1_layer_1_marks", "type": "rect", "style": ["tick", "boxplot-median"], "aria": false, "from": {"data": "data_1"}, "encode": { "update": { "opacity": {"value": 0.7}, "fill": {"value": "white"}, "tooltip": { "signal": "{\"Max of population\": format(datum[\"max_people\"], \"\"), \"Q3 of population\": format(datum[\"upper_box_people\"], \"\"), \"Median of population\": format(datum[\"mid_box_people\"], \"\"), \"Q1 of population\": format(datum[\"lower_box_people\"], \"\"), \"Min of population\": format(datum[\"min_people\"], \"\"), \"age\": isValid(datum[\"age\"]) ? datum[\"age\"] : \"\"+datum[\"age\"]}" }, "xc": {"scale": "x", "field": "mid_box_people"}, "yc": {"scale": "y", "field": "age", "band": 0.5}, "height": {"value": 14}, "width": {"value": 1} } } }, { "name": "layer_1_marks", "type": "symbol", "style": ["circle"], "from": {"data": "data_2"}, "encode": { "update": { "opacity": {"value": 0.2}, "fill": {"value": "black"}, "ariaRoleDescription": {"value": "circle"}, "description": { "signal": "\"age: \" + (isValid(datum[\"age\"]) ? datum[\"age\"] : \"\"+datum[\"age\"]) + \"; population: \" + (format(datum[\"people\"], \"\"))" }, "x": {"scale": "x", "field": "people"}, "y": {"scale": "y", "field": "age", "band": 0.5}, "shape": {"value": "circle"} } } } ], "scales": [ { "name": "x", "type": "linear", "domain": { "fields": [ {"data": "data_0", "field": "lower_whisker_people"}, {"data": "data_0", "field": "lower_box_people"}, {"data": "data_0", "field": "upper_box_people"}, {"data": "data_0", "field": "upper_whisker_people"}, {"data": "data_1", "field": "lower_box_people"}, {"data": "data_1", "field": "upper_box_people"}, {"data": "data_1", "field": "mid_box_people"}, {"data": "data_2", "field": "people"} ] }, "range": [0, {"signal": "width"}], "nice": true, "zero": true }, { "name": "y", "type": "band", "domain": { "fields": [ {"data": "data_0", "field": "age"}, {"data": "data_1", "field": "age"}, {"data": "data_2", "field": "age"} ], "sort": true }, "range": {"step": {"signal": "y_step"}}, "paddingInner": 0, "paddingOuter": 0 } ], "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": "x", "orient": "bottom", "grid": false, "title": "population", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(width/40)"}, "zindex": 0 }, {"scale": "y", "orient": "left", "grid": false, "title": "age", "zindex": 0} ]}