{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "width": 800, "height": 500, "style": "cell", "data": [ { "name": "source_0", "url": "https://raw.githubusercontent.com/vega/vega-datasets/master/data/co2-concentration.csv", "format": { "type": "csv", "parse": {"Date": "utc:'%Y-%m-%d'"}, "delimiter": "," }, "transform": [ {"type": "formula", "expr": "year(datum.Date)", "as": "year"}, {"type": "formula", "expr": "floor(datum.year / 10)", "as": "decade"}, { "type": "formula", "expr": "(datum.year % 10) + (month(datum.Date)/12)", "as": "scaled_date" } ] }, { "name": "data_0", "source": "source_0", "transform": [ { "type": "aggregate", "groupby": ["decade"], "ops": ["max", "argmax", "min", "argmin"], "fields": [ "scaled_date", "scaled_date", "scaled_date", "scaled_date" ], "as": [ "max_scaled_date", "argmax_scaled_date", "min_scaled_date", "argmin_scaled_date" ] } ] }, { "name": "data_1", "source": "data_0", "transform": [ { "type": "filter", "expr": "isValid(datum[\"max_scaled_date\"]) && isFinite(+datum[\"max_scaled_date\"]) && isValid(datum[\"argmax_scaled_date\"][\"CO2\"]) && isFinite(+datum[\"argmax_scaled_date\"][\"CO2\"])" } ] }, { "name": "data_2", "source": "data_0", "transform": [ { "type": "filter", "expr": "isValid(datum[\"min_scaled_date\"]) && isFinite(+datum[\"min_scaled_date\"]) && isValid(datum[\"argmin_scaled_date\"][\"CO2\"]) && isFinite(+datum[\"argmin_scaled_date\"][\"CO2\"])" } ] } ], "marks": [ { "name": "layer_0_pathgroup", "type": "group", "from": { "facet": { "name": "faceted_path_layer_0_main", "data": "source_0", "groupby": ["decade"] } }, "encode": { "update": { "width": {"field": {"group": "width"}}, "height": {"field": {"group": "height"}} } }, "marks": [ { "name": "layer_0_marks", "type": "line", "style": ["line"], "sort": {"field": "datum[\"scaled_date\"]"}, "from": {"data": "faceted_path_layer_0_main"}, "encode": { "update": { "stroke": {"scale": "color", "field": "decade"}, "description": { "signal": "\"Year into Decade: \" + (format(datum[\"scaled_date\"], \"\")) + \"; CO2 concentration in ppm: \" + (format(datum[\"CO2\"], \"\")) + \"; decade: \" + (isValid(datum[\"decade\"]) ? datum[\"decade\"] : \"\"+datum[\"decade\"])" }, "x": {"scale": "x", "field": "scaled_date"}, "y": {"scale": "y", "field": "CO2"}, "defined": { "signal": "isValid(datum[\"scaled_date\"]) && isFinite(+datum[\"scaled_date\"]) && isValid(datum[\"CO2\"]) && isFinite(+datum[\"CO2\"])" } } } } ] }, { "name": "layer_1_marks", "type": "text", "style": ["text"], "aria": false, "from": {"data": "data_2"}, "encode": { "update": { "baseline": {"value": "top"}, "fill": {"scale": "color", "field": "decade"}, "x": [ { "test": "!isValid(datum[\"min_scaled_date\"]) || !isFinite(+datum[\"min_scaled_date\"])", "value": 0 }, {"scale": "x", "field": "min_scaled_date"} ], "y": [ { "test": "!isValid(datum[\"argmin_scaled_date\"][\"CO2\"]) || !isFinite(+datum[\"argmin_scaled_date\"][\"CO2\"])", "field": {"group": "height"} }, {"scale": "y", "field": "argmin_scaled_date[\"CO2\"]"} ], "text": { "signal": "isValid(datum[\"argmin_scaled_date\"][\"year\"]) ? datum[\"argmin_scaled_date\"][\"year\"] : \"\"+datum[\"argmin_scaled_date\"][\"year\"]" } } } }, { "name": "layer_2_marks", "type": "text", "style": ["text"], "aria": false, "from": {"data": "data_1"}, "encode": { "update": { "fill": {"scale": "color", "field": "decade"}, "x": [ { "test": "!isValid(datum[\"max_scaled_date\"]) || !isFinite(+datum[\"max_scaled_date\"])", "value": 0 }, {"scale": "x", "field": "max_scaled_date"} ], "y": [ { "test": "!isValid(datum[\"argmax_scaled_date\"][\"CO2\"]) || !isFinite(+datum[\"argmax_scaled_date\"][\"CO2\"])", "field": {"group": "height"} }, {"scale": "y", "field": "argmax_scaled_date[\"CO2\"]"} ], "text": { "signal": "isValid(datum[\"argmax_scaled_date\"][\"year\"]) ? datum[\"argmax_scaled_date\"][\"year\"] : \"\"+datum[\"argmax_scaled_date\"][\"year\"]" }, "baseline": {"value": "middle"} } } } ], "scales": [ { "name": "x", "type": "linear", "domain": { "fields": [ {"data": "source_0", "field": "scaled_date"}, {"data": "data_2", "field": "min_scaled_date"}, {"data": "data_1", "field": "max_scaled_date"} ] }, "range": [0, {"signal": "width"}], "nice": true, "zero": false }, { "name": "y", "type": "linear", "domain": { "fields": [ {"data": "source_0", "field": "CO2"}, {"data": "data_2", "field": "argmin_scaled_date[\"CO2\"]"}, {"data": "data_1", "field": "argmax_scaled_date[\"CO2\"]"} ] }, "range": [{"signal": "height"}, 0], "zero": false, "nice": true }, { "name": "color", "type": "ordinal", "domain": { "fields": [ {"data": "source_0", "field": "decade"}, {"data": "data_2", "field": "decade"}, {"data": "data_1", "field": "decade"} ], "sort": true }, "range": {"scheme": "magma"}, "interpolate": "hcl" } ], "axes": [ { "scale": "x", "orient": "bottom", "tickCount": 11, "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": "Year into Decade", "tickCount": 11, "labelFlush": true, "labelOverlap": true, "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "CO2 concentration in ppm", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ], "config": {"style": {"text": {"align": "left", "dx": 3, "dy": 1}}} }