{ "$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_facet_domain", "source": "source_0", "transform": [ { "type": "aggregate", "groupby": ["site"], "fields": ["yield"], "ops": ["median"], "as": ["median_yield"] } ] }, { "name": "trellis_barley_facet_domain_row", "transform": [ { "type": "sequence", "start": 0, "stop": { "signal": "ceil(length(data(\"trellis_barley_facet_domain\")) / 2)" } } ] }, { "name": "trellis_barley_facet_domain_column", "transform": [ { "type": "sequence", "start": 0, "stop": { "signal": "min(length(data(\"trellis_barley_facet_domain\")), 2)" } } ] }, { "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\"])" } ] } ], "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, "bounds": "full", "align": "all", "columns": 2}, "marks": [ { "name": "facet-title", "type": "group", "role": "column-title", "title": {"text": "site", "style": "guide-title", "offset": 10} }, { "name": "trellis_barley_row_header", "type": "group", "role": "row-header", "from": {"data": "trellis_barley_facet_domain_row"}, "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", "from": {"data": "trellis_barley_facet_domain_column"}, "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", "title": { "text": { "signal": "isValid(parent[\"site\"]) ? parent[\"site\"] : \"\"+parent[\"site\"]" }, "style": "guide-label", "frame": "group", "offset": 10 }, "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": [ { "source": "trellis_barley_facet", "name": "data_0", "transform": [ { "type": "aggregate", "groupby": ["variety", "year"], "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_marks", "type": "symbol", "style": ["point"], "from": {"data": "data_0"}, "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"} } } } ], "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": {"data": "data_2", "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"}}}} } ] }