Created
January 30, 2023 13:06
-
-
Save Giammaria/21d167c226054e60c23b55be70a78ada to your computer and use it in GitHub Desktop.
Matrix With Multiple Aggregations - Mon Jan 30 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "$schema": "https://vega.github.io/schema/vega-lite/v5.json", | |
| "data": { | |
| "name": "dataset", | |
| "values": [ | |
| {"B1": 2, "B2": 7, "B3": 24}, | |
| {"B1": 6, "B2": 12, "B3": 5}, | |
| {"B1": 15, "B2": 2, "B3": 56}, | |
| {"B1": 15, "B2": 12, "B3": 13} | |
| ] | |
| }, | |
| "transform": [ | |
| {"window": [{"op": "row_number", "as": "RN"}]}, | |
| {"calculate": "'A'+toString(datum['RN'])", "as": "Row"}, | |
| {"fold": ["B1", "B2", "B3"], "as": ["B", "Value"]}, | |
| { | |
| "window": [{"field": "Value", "as": "Total", "op": "sum"}], | |
| "frame": [null, null], | |
| "groupby": ["B"] | |
| }, | |
| { | |
| "window": [{"field": "Value", "as": "Average", "op": "average"}], | |
| "frame": [null, null], | |
| "groupby": ["B"] | |
| }, | |
| { | |
| "window": [{"field": "Value", "as": "Max", "op": "max"}], | |
| "frame": [null, null], | |
| "groupby": ["B"] | |
| } | |
| ], | |
| "spacing": 0, | |
| "vconcat": [ | |
| { | |
| "name": "Matrix", | |
| "width": {"step": 30}, | |
| "height": {"step": 30}, | |
| "encoding": { | |
| "x": { | |
| "field": "B", | |
| "type": "nominal", | |
| "axis": {"orient": "top", "title": null, "labelAngle": 0} | |
| }, | |
| "y": {"field": "Row", "axis": {"title": null}} | |
| }, | |
| "layer": [ | |
| {"mark": {"type": "rect", "stroke": "#eee", "fillOpacity": 0}}, | |
| {"mark": "text", "encoding": {"text": {"field": "Value"}}} | |
| ] | |
| }, | |
| { | |
| "name": "Total", | |
| "transform": [ | |
| {"window": [{"op": "row_number", "as": "aggRN"}], "groupby": ["B"]}, | |
| {"filter": "datum['aggRN']==1"} | |
| ], | |
| "width": {"step": 30}, | |
| "encoding": { | |
| "x": { | |
| "field": "Total", | |
| "type": "nominal", | |
| "axis": null, | |
| "sort": {"field": "B"} | |
| }, | |
| "y": { | |
| "field": "1", | |
| "axis": { | |
| "title": "Total", | |
| "titleAngle": 0, | |
| "titleAnchor": "end", | |
| "titleFontSize": 12, | |
| "titleFontWeight": "bold", | |
| "titleBaseline": "bottom", | |
| "titleY": 15 | |
| } | |
| } | |
| }, | |
| "layer": [ | |
| {"mark": {"type": "rect", "fillOpacity": 0, "strokeOpacity": 0}}, | |
| { | |
| "mark": {"type": "text", "fontWeight": "bold"}, | |
| "encoding": {"text": {"field": "Total"}} | |
| } | |
| ] | |
| }, | |
| { | |
| "name": "Sub Aggregate 1", | |
| "transform": [ | |
| {"window": [{"op": "row_number", "as": "aggRN"}], "groupby": ["B"]}, | |
| {"filter": "datum['aggRN']==1"} | |
| ], | |
| "width": {"step": 30}, | |
| "encoding": { | |
| "x": { | |
| "field": "Average", | |
| "type": "nominal", | |
| "axis": null, | |
| "sort": {"field": "B"} | |
| }, | |
| "y": { | |
| "field": "1", | |
| "axis": { | |
| "title": "Average", | |
| "titleAngle": 0, | |
| "titleAnchor": "end", | |
| "titleFontSize": 12, | |
| "titleFontWeight": "bold", | |
| "titleBaseline": "bottom", | |
| "titleY": 15 | |
| } | |
| } | |
| }, | |
| "layer": [ | |
| {"mark": {"type": "rect", "fillOpacity": 0, "strokeOpacity": 0}}, | |
| { | |
| "mark": {"type": "text", "fontWeight": "bold"}, | |
| "encoding": {"text": {"field": "Average"}} | |
| } | |
| ] | |
| }, | |
| { | |
| "name": "Sub Aggregate 2", | |
| "transform": [ | |
| {"window": [{"op": "row_number", "as": "aggRN"}], "groupby": ["B"]}, | |
| {"filter": "datum['aggRN']==1"} | |
| ], | |
| "width": {"step": 30}, | |
| "encoding": { | |
| "x": { | |
| "field": "Max", | |
| "type": "nominal", | |
| "axis": null, | |
| "sort": {"field": "B"} | |
| }, | |
| "y": { | |
| "field": "1", | |
| "axis": { | |
| "title": "Max", | |
| "titleAngle": 0, | |
| "titleAnchor": "end", | |
| "titleFontSize": 12, | |
| "titleFontWeight": "bold", | |
| "titleBaseline": "bottom", | |
| "titleY": 15 | |
| } | |
| } | |
| }, | |
| "layer": [ | |
| {"mark": {"type": "rect", "fillOpacity": 0, "strokeOpacity": 0}}, | |
| { | |
| "mark": {"type": "text", "fontWeight": "bold"}, | |
| "encoding": {"text": {"field": "Max"}} | |
| } | |
| ] | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment