{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "A bubble plot showing the correlation between health and income for 187 countries in the world (modified from an example in Lisa Charlotte Rost's blog post 'One Chart, Twelve Charting Libraries' --http://lisacharlotterost.github.io/2016/05/17/one-chart-code/).", "background": "white", "padding": 5, "width": 500, "height": 300, "style": "cell", "data": [ {"name": "view_store"}, { "name": "source_0", "url": "https://raw.githubusercontent.com/vega/vega-datasets/master/data/gapminder-health-income.csv", "format": {"type": "csv", "delimiter": ","}, "transform": [ { "type": "filter", "expr": "isValid(datum[\"health\"]) && isFinite(+datum[\"health\"]) && isValid(datum[\"income\"]) && isFinite(+datum[\"income\"]) && isValid(datum[\"population\"]) && isFinite(+datum[\"population\"])" } ] } ], "signals": [ { "name": "unit", "value": {}, "on": [ {"events": "mousemove", "update": "isTuple(group()) ? group() : unit"} ] }, {"name": "view", "update": "vlSelectionResolve(\"view_store\", \"union\")"}, { "name": "view_income", "on": [ {"events": [{"source": "view", "type": "dblclick"}], "update": "null"}, { "events": {"signal": "view_translate_delta"}, "update": "panLog(view_translate_anchor.extent_x, -view_translate_delta.x / width)" }, { "events": {"signal": "view_zoom_delta"}, "update": "zoomLog(domain(\"x\"), view_zoom_anchor.x, view_zoom_delta)" } ] }, { "name": "view_health", "on": [ {"events": [{"source": "view", "type": "dblclick"}], "update": "null"}, { "events": {"signal": "view_translate_delta"}, "update": "panLinear(view_translate_anchor.extent_y, view_translate_delta.y / height)" }, { "events": {"signal": "view_zoom_delta"}, "update": "zoomLinear(domain(\"y\"), view_zoom_anchor.y, view_zoom_delta)" } ] }, { "name": "view_tuple", "on": [ { "events": [{"signal": "view_income || view_health"}], "update": "view_income && view_health ? {unit: \"\", fields: view_tuple_fields, values: [view_income,view_health]} : null" } ] }, { "name": "view_tuple_fields", "value": [ {"field": "income", "channel": "x", "type": "R"}, {"field": "health", "channel": "y", "type": "R"} ] }, { "name": "view_translate_anchor", "value": {}, "on": [ { "events": [{"source": "scope", "type": "mousedown"}], "update": "{x: x(unit), y: y(unit), extent_x: domain(\"x\"), extent_y: domain(\"y\")}" } ] }, { "name": "view_translate_delta", "value": {}, "on": [ { "events": [ { "source": "window", "type": "mousemove", "consume": true, "between": [ {"source": "scope", "type": "mousedown"}, {"source": "window", "type": "mouseup"} ] } ], "update": "{x: view_translate_anchor.x - x(unit), y: view_translate_anchor.y - y(unit)}" } ] }, { "name": "view_zoom_anchor", "on": [ { "events": [{"source": "scope", "type": "wheel", "consume": true}], "update": "{x: invert(\"x\", x(unit)), y: invert(\"y\", y(unit))}" } ] }, { "name": "view_zoom_delta", "on": [ { "events": [{"source": "scope", "type": "wheel", "consume": true}], "force": true, "update": "pow(1.001, event.deltaY * pow(16, event.deltaMode))" } ] }, { "name": "view_modify", "on": [ { "events": {"signal": "view_tuple"}, "update": "modify(\"view_store\", view_tuple, true)" } ] } ], "marks": [ { "name": "marks", "type": "symbol", "clip": true, "style": ["circle"], "interactive": true, "from": {"data": "source_0"}, "encode": { "update": { "opacity": {"value": 0.7}, "fill": {"value": "#000"}, "ariaRoleDescription": {"value": "circle"}, "description": { "signal": "\"health: \" + (format(datum[\"health\"], \"\")) + \"; income: \" + (format(datum[\"income\"], \"\")) + \"; population: \" + (format(datum[\"population\"], \"\"))" }, "x": {"scale": "x", "field": "income"}, "y": [ { "test": "!isValid(datum[\"health\"]) || !isFinite(+datum[\"health\"])", "field": {"group": "height"} }, {"scale": "y", "field": "health"} ], "size": {"scale": "size", "field": "population"}, "shape": {"value": "circle"} } } } ], "scales": [ { "name": "x", "type": "log", "domain": {"data": "source_0", "field": "income"}, "domainRaw": {"signal": "view[\"income\"]"}, "range": [0, {"signal": "width"}], "nice": true }, { "name": "y", "type": "linear", "domain": {"data": "source_0", "field": "health"}, "domainRaw": {"signal": "view[\"health\"]"}, "range": [{"signal": "height"}, 0], "zero": false, "nice": true }, { "name": "size", "type": "linear", "domain": {"data": "source_0", "field": "population"}, "range": [0, 361], "zero": true } ], "axes": [ { "scale": "x", "orient": "bottom", "gridScale": "y", "grid": true, "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": "income", "labelFlush": true, "labelOverlap": "greedy", "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "health", "minExtent": 30, "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ], "legends": [ { "size": "size", "symbolType": "circle", "title": "population", "encode": { "symbols": { "update": { "fill": {"value": "#000"}, "opacity": {"value": 0.7}, "stroke": {"value": "transparent"} } } } } ] }