{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "A ranged dot plot that uses 'layer' to convey changing life expectancy for the five most populous countries (between 1955 and 2000).", "background": "white", "padding": 5, "width": 200, "style": "cell", "data": [ { "name": "source_0", "url": "data/countries.json", "format": { "type": "json", "parse": {"country": "string", "year": "number"} }, "transform": [ { "type": "filter", "expr": "indexof([\"China\",\"India\",\"United States\",\"Indonesia\",\"Brazil\"], datum[\"country\"]) !== -1" }, { "type": "filter", "expr": "indexof([1955,2000], datum[\"year\"]) !== -1" } ] }, { "name": "data_0", "source": "source_0", "transform": [ { "type": "filter", "expr": "isValid(datum[\"life_expect\"]) && isFinite(+datum[\"life_expect\"])" } ] } ], "signals": [ {"name": "y_step", "value": 20}, { "name": "height", "update": "bandspace(domain('y').length, 1, 0.5) * y_step" } ], "marks": [ { "name": "layer_0_pathgroup", "type": "group", "from": { "facet": { "name": "faceted_path_layer_0_main", "data": "source_0", "groupby": ["country"] } }, "encode": { "update": { "width": {"field": {"group": "width"}}, "height": {"field": {"group": "height"}} } }, "marks": [ { "name": "layer_0_marks", "type": "line", "style": ["line"], "sort": {"field": "datum[\"country\"]"}, "from": {"data": "faceted_path_layer_0_main"}, "encode": { "update": { "stroke": {"value": "#db646f"}, "description": { "signal": "\"Life Expectancy (years): \" + (format(datum[\"life_expect\"], \"\")) + \"; Country: \" + (isValid(datum[\"country\"]) ? datum[\"country\"] : \"\"+datum[\"country\"]) + \"; country: \" + (isValid(datum[\"country\"]) ? datum[\"country\"] : \"\"+datum[\"country\"])" }, "x": {"scale": "x", "field": "life_expect"}, "y": {"scale": "y", "field": "country"}, "defined": { "signal": "isValid(datum[\"life_expect\"]) && isFinite(+datum[\"life_expect\"])" } } } } ] }, { "name": "layer_1_marks", "type": "symbol", "style": ["point"], "from": {"data": "data_0"}, "encode": { "update": { "opacity": {"value": 1}, "fill": {"scale": "color", "field": "year"}, "ariaRoleDescription": {"value": "point"}, "description": { "signal": "\"Life Expectancy (years): \" + (format(datum[\"life_expect\"], \"\")) + \"; Country: \" + (isValid(datum[\"country\"]) ? datum[\"country\"] : \"\"+datum[\"country\"]) + \"; Year: \" + (isValid(datum[\"year\"]) ? datum[\"year\"] : \"\"+datum[\"year\"])" }, "x": {"scale": "x", "field": "life_expect"}, "y": {"scale": "y", "field": "country"}, "size": {"value": 100} } } } ], "scales": [ { "name": "x", "type": "linear", "domain": { "fields": [ {"data": "source_0", "field": "life_expect"}, {"data": "data_0", "field": "life_expect"} ] }, "range": [0, {"signal": "width"}], "nice": true, "zero": true }, { "name": "y", "type": "point", "domain": { "fields": [ {"data": "source_0", "field": "country"}, {"data": "data_0", "field": "country"} ], "sort": true }, "range": {"step": {"signal": "y_step"}}, "padding": 0.5 }, { "name": "color", "type": "ordinal", "domain": [1955, 2000], "range": ["#e6959c", "#911a24"], "interpolate": "hcl" } ], "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": "Life Expectancy (years)", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(width/40)"}, "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "Country", "domain": false, "minExtent": 70, "offset": 5, "ticks": false, "zindex": 0 } ], "legends": [ { "title": "Year", "fill": "color", "symbolType": "circle", "encode": {"symbols": {"update": {"opacity": {"value": 1}}}} } ] }