{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "Slope graph showing the change in yield for different barley sites. It shows the error in the year labels for the Morris site.", "background": "white", "padding": 5, "height": 200, "style": "cell", "data": [ { "name": "source_0", "url": "https://raw.githubusercontent.com/vega/vega-datasets/master/data/barley.json", "format": {"type": "json"}, "transform": [ { "type": "aggregate", "groupby": ["year", "site"], "ops": ["mean"], "fields": ["yield"], "as": ["mean_yield"] } ] } ], "signals": [ {"name": "x_step", "value": 50}, { "name": "width", "update": "bandspace(domain('x').length, 1, 0.5) * x_step" } ], "marks": [ { "name": "pathgroup", "type": "group", "from": { "facet": { "name": "faceted_path_main", "data": "source_0", "groupby": ["site"] } }, "encode": { "update": { "width": {"field": {"group": "width"}}, "height": {"field": {"group": "height"}} } }, "marks": [ { "name": "marks", "type": "line", "style": ["line"], "sort": {"field": "datum[\"year\"]"}, "from": {"data": "faceted_path_main"}, "encode": { "update": { "stroke": {"scale": "color", "field": "site"}, "description": { "signal": "\"year: \" + (isValid(datum[\"year\"]) ? datum[\"year\"] : \"\"+datum[\"year\"]) + \"; Mean of yield: \" + (format(datum[\"mean_yield\"], \"\")) + \"; site: \" + (isValid(datum[\"site\"]) ? datum[\"site\"] : \"\"+datum[\"site\"])" }, "x": {"scale": "x", "field": "year"}, "y": {"scale": "y", "field": "mean_yield"}, "defined": { "signal": "isValid(datum[\"mean_yield\"]) && isFinite(+datum[\"mean_yield\"])" } } } } ] } ], "scales": [ { "name": "x", "type": "point", "domain": {"data": "source_0", "field": "year", "sort": true}, "range": {"step": {"signal": "x_step"}}, "padding": 0.5 }, { "name": "y", "type": "linear", "domain": {"data": "source_0", "field": "mean_yield"}, "range": [{"signal": "height"}, 0], "nice": true, "zero": true }, { "name": "color", "type": "ordinal", "domain": {"data": "source_0", "field": "site", "sort": true}, "range": "category" } ], "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": "year", "labelAlign": "right", "labelAngle": 270, "labelBaseline": "middle", "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "Mean of yield", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ], "legends": [{"stroke": "color", "symbolType": "stroke", "title": "site"}] }