{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "The Trellis display by Becker et al. helped establish small multiples as a “powerful mechanism for understanding interactions in studies of how a response depends on explanatory variables”. Here we reproduce a trellis of Barley yields from the 1930s, complete with main-effects ordering to facilitate comparison.", "background": "white", "padding": 5, "data": [ {"name": "source_0", "url": "data/barley.json", "format": {"type": "json"}}, { "name": "trellis_barley_row_domain", "source": "source_0", "transform": [ { "type": "aggregate", "groupby": ["site"], "fields": ["yield"], "ops": ["median"], "as": ["median_yield"] } ] }, { "name": "data_2", "source": "source_0", "transform": [ { "type": "aggregate", "groupby": ["variety", "year", "site"], "ops": ["median"], "fields": ["yield"], "as": ["median_yield"] }, { "type": "filter", "expr": "isValid(datum[\"median_yield\"]) && isFinite(+datum[\"median_yield\"])" } ] }, { "name": "data_3", "source": "source_0", "transform": [ { "type": "aggregate", "groupby": ["site"], "ops": ["median"], "fields": ["yield"], "as": ["median_yield"] }, { "type": "filter", "expr": "isValid(datum[\"median_yield\"]) && isFinite(+datum[\"median_yield\"])" } ] } ], "signals": [ {"name": "trellis_barley_child_width", "value": 200}, {"name": "trellis_barley_y_step", "value": 12}, { "name": "trellis_barley_child_height", "update": "bandspace(domain('trellis_barley_y').length, 1, 0.5) * trellis_barley_y_step" } ], "layout": { "padding": 20, "offset": {"rowTitle": 10}, "columns": 1, "bounds": "full", "align": "all" }, "marks": [ { "name": "row-title", "type": "group", "role": "row-title", "title": { "text": "site", "orient": "left", "style": "guide-title", "offset": 10 } }, { "name": "trellis_barley_row_header", "type": "group", "role": "row-header", "from": {"data": "trellis_barley_row_domain"}, "sort": {"field": "datum[\"median_yield\"]", "order": "ascending"}, "title": { "text": { "signal": "isValid(parent[\"site\"]) ? parent[\"site\"] : \"\"+parent[\"site\"]" }, "orient": "left", "style": "guide-label", "frame": "group", "offset": 10 }, "encode": { "update": {"height": {"signal": "trellis_barley_child_height"}} }, "axes": [ { "scale": "trellis_barley_y", "orient": "left", "grid": false, "title": "variety", "zindex": 0 } ] }, { "name": "trellis_barley_column_footer", "type": "group", "role": "column-footer", "encode": {"update": {"width": {"signal": "trellis_barley_child_width"}}}, "axes": [ { "scale": "trellis_barley_x", "orient": "bottom", "grid": false, "title": "Median of yield", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(trellis_barley_child_width/40)"}, "zindex": 0 } ] }, { "name": "trellis_barley_cell", "type": "group", "style": "cell", "from": { "facet": { "name": "trellis_barley_facet", "data": "source_0", "groupby": ["site"], "aggregate": { "fields": ["yield"], "ops": ["median"], "as": ["median_yield_by_site"] } } }, "sort": { "field": ["datum[\"median_yield_by_site\"]"], "order": ["ascending"] }, "data": [ { "name": "data_1", "source": "trellis_barley_facet", "transform": [ { "type": "aggregate", "groupby": ["variety", "year"], "ops": ["median"], "fields": ["yield"], "as": ["median_yield"] }, { "type": "filter", "expr": "isValid(datum[\"median_yield\"]) && isFinite(+datum[\"median_yield\"])" } ] }, { "name": "data_2", "source": "trellis_barley_facet", "transform": [ { "type": "aggregate", "groupby": [], "ops": ["median"], "fields": ["yield"], "as": ["median_yield"] }, { "type": "filter", "expr": "isValid(datum[\"median_yield\"]) && isFinite(+datum[\"median_yield\"])" } ] } ], "encode": { "update": { "width": {"signal": "trellis_barley_child_width"}, "height": {"signal": "trellis_barley_child_height"} } }, "marks": [ { "name": "trellis_barley_child_layer_0_marks", "type": "symbol", "style": ["point"], "from": {"data": "data_1"}, "encode": { "update": { "fill": {"value": "transparent"}, "stroke": {"scale": "trellis_barley_color", "field": "year"}, "ariaRoleDescription": {"value": "point"}, "description": { "signal": "\"Median of yield: \" + (format(datum[\"median_yield\"], \"\")) + \"; variety: \" + (isValid(datum[\"variety\"]) ? datum[\"variety\"] : \"\"+datum[\"variety\"]) + \"; year: \" + (isValid(datum[\"year\"]) ? datum[\"year\"] : \"\"+datum[\"year\"])" }, "x": {"scale": "trellis_barley_x", "field": "median_yield"}, "y": {"scale": "trellis_barley_y", "field": "variety"} } } }, { "name": "trellis_barley_child_layer_1_marks", "type": "rule", "style": ["rule"], "from": {"data": "data_2"}, "encode": { "update": { "stroke": {"value": "black"}, "description": { "signal": "\"Median of yield: \" + (format(datum[\"median_yield\"], \"\"))" }, "x": {"scale": "trellis_barley_x", "field": "median_yield"}, "y": {"value": 0}, "y2": {"field": {"group": "height"}} } } } ], "axes": [ { "scale": "trellis_barley_x", "orient": "bottom", "gridScale": "trellis_barley_y", "grid": true, "tickCount": {"signal": "ceil(trellis_barley_child_width/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 } ] } ], "scales": [ { "name": "trellis_barley_x", "type": "linear", "domain": { "fields": [ {"data": "data_2", "field": "median_yield"}, {"data": "data_3", "field": "median_yield"} ] }, "range": [0, {"signal": "trellis_barley_child_width"}], "zero": false, "nice": true }, { "name": "trellis_barley_y", "type": "point", "domain": { "data": "source_0", "field": "variety", "sort": {"op": "median", "field": "yield", "order": "descending"} }, "range": {"step": {"signal": "trellis_barley_y_step"}}, "padding": 0.5 }, { "name": "trellis_barley_color", "type": "ordinal", "domain": {"data": "data_2", "field": "year", "sort": true}, "range": "category" } ], "legends": [ { "stroke": "trellis_barley_color", "symbolType": "circle", "title": "year", "encode": {"symbols": {"update": {"fill": {"value": "transparent"}}}} } ] }