{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "Stock price mean per quarter broken down by years.", "background": "white", "padding": 5, "data": [ { "name": "source_0", "url": "data/stocks.csv", "format": {"type": "csv", "parse": {"date": "date"}}, "transform": [ { "field": "date", "type": "timeunit", "units": ["year"], "as": ["year_date", "year_date_end"] }, { "field": "date", "type": "timeunit", "units": ["quarter"], "as": ["quarter_date", "quarter_date_end"] }, { "type": "aggregate", "groupby": ["quarter_date", "symbol", "year_date"], "ops": ["mean"], "fields": ["price"], "as": ["mean_price"] }, { "type": "filter", "expr": "isValid(datum[\"mean_price\"]) && isFinite(+datum[\"mean_price\"])" } ] }, { "name": "column_domain", "source": "source_0", "transform": [{"type": "aggregate", "groupby": ["year_date"]}] } ], "signals": [ {"name": "x_step", "value": 20}, { "name": "child_width", "update": "bandspace(domain('x').length, 1, 0.5) * x_step" }, {"name": "child_height", "value": 200} ], "layout": { "padding": 20, "offset": {"columnTitle": 10}, "columns": {"signal": "length(data('column_domain'))"}, "bounds": "full", "align": "all" }, "marks": [ { "name": "column-title", "type": "group", "role": "column-title", "title": {"text": "date (year)", "style": "guide-title", "offset": 10} }, { "name": "row_header", "type": "group", "role": "row-header", "encode": {"update": {"height": {"signal": "child_height"}}}, "axes": [ { "scale": "y", "orient": "left", "grid": false, "title": "Mean of price", "labelOverlap": true, "tickCount": {"signal": "ceil(child_height/40)"}, "zindex": 0 } ] }, { "name": "column_header", "type": "group", "role": "column-header", "from": {"data": "column_domain"}, "sort": {"field": "datum[\"year_date\"]", "order": "ascending"}, "title": { "text": { "signal": "timeFormat(parent[\"year_date\"], timeUnitSpecifier([\"year\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"}))" }, "style": "guide-label", "frame": "group", "offset": 10 }, "encode": {"update": {"width": {"signal": "child_width"}}} }, { "name": "column_footer", "type": "group", "role": "column-footer", "from": {"data": "column_domain"}, "sort": {"field": "datum[\"year_date\"]", "order": "ascending"}, "encode": {"update": {"width": {"signal": "child_width"}}}, "axes": [ { "scale": "x", "orient": "bottom", "grid": false, "title": "date (quarter)", "format": { "signal": "timeUnitSpecifier([\"quarter\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"})" }, "formatType": "time", "labelOverlap": true, "zindex": 0 } ] }, { "name": "cell", "type": "group", "style": "cell", "from": { "facet": {"name": "facet", "data": "source_0", "groupby": ["year_date"]} }, "sort": {"field": ["datum[\"year_date\"]"], "order": ["ascending"]}, "encode": { "update": { "width": {"signal": "child_width"}, "height": {"signal": "child_height"} } }, "marks": [ { "name": "child_marks", "type": "symbol", "style": ["point"], "from": {"data": "facet"}, "encode": { "update": { "fill": {"value": "transparent"}, "stroke": {"scale": "color", "field": "symbol"}, "ariaRoleDescription": {"value": "point"}, "description": { "signal": "\"date (quarter): \" + (timeFormat(datum[\"quarter_date\"], timeUnitSpecifier([\"quarter\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"}))) + \"; Mean of price: \" + (format(datum[\"mean_price\"], \"\")) + \"; symbol: \" + (isValid(datum[\"symbol\"]) ? datum[\"symbol\"] : \"\"+datum[\"symbol\"])" }, "x": {"scale": "x", "field": "quarter_date"}, "y": {"scale": "y", "field": "mean_price"} } } } ], "axes": [ { "scale": "y", "orient": "left", "gridScale": "x", "grid": true, "tickCount": {"signal": "ceil(child_height/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 } ] } ], "scales": [ { "name": "x", "type": "point", "domain": {"data": "source_0", "field": "quarter_date", "sort": true}, "range": {"step": {"signal": "x_step"}}, "padding": 0.5 }, { "name": "y", "type": "linear", "domain": {"data": "source_0", "field": "mean_price"}, "range": [{"signal": "child_height"}, 0], "nice": true, "zero": true }, { "name": "color", "type": "ordinal", "domain": {"data": "source_0", "field": "symbol", "sort": true}, "range": "category" } ], "legends": [ { "stroke": "color", "symbolType": "circle", "title": "symbol", "encode": {"symbols": {"update": {"fill": {"value": "transparent"}}}} } ] }