Last active
October 7, 2015 12:50
-
-
Save randyzwitch/7ced012dde274a8c80ed to your computer and use it in GitHub Desktop.
Vega boxplot using mtcars
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
| { | |
| "name": "boxplot", | |
| "height": 200, | |
| "padding": "auto", | |
| "width": 600, | |
| "signals": [ | |
| { | |
| "name": "boxSize", | |
| "init": 40 | |
| } | |
| ], | |
| "axes": [ | |
| { | |
| "type": "x", | |
| "scale": "x" | |
| }, | |
| { | |
| "offset": 5, | |
| "properties": { | |
| "axis": { | |
| "stroke": { | |
| "value": "transparent" | |
| } | |
| } | |
| }, | |
| "type": "y", | |
| "scale": "y", | |
| "tickSize": 0 | |
| } | |
| ], | |
| "scales": [ | |
| { | |
| "name": "y", | |
| "points": true, | |
| "padding": 1.5, | |
| "range": "height", | |
| "domain": { | |
| "data": "table", | |
| "field": "x" | |
| }, | |
| "type": "ordinal", | |
| "round": true | |
| }, | |
| { | |
| "name": "x", | |
| "nice": true, | |
| "range": "width", | |
| "domain": { | |
| "data": "table", | |
| "field": [ | |
| "y" | |
| ] | |
| }, | |
| "type": "linear", | |
| "round": true | |
| } | |
| ], | |
| "data": [ | |
| { | |
| "name": "table", | |
| "values": [ | |
| { | |
| "x": 6, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 21 | |
| }, | |
| { | |
| "x": 6, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 21 | |
| }, | |
| { | |
| "x": 4, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 22.8 | |
| }, | |
| { | |
| "x": 6, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 21.4 | |
| }, | |
| { | |
| "x": 8, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 18.7 | |
| }, | |
| { | |
| "x": 6, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 18.1 | |
| }, | |
| { | |
| "x": 8, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 14.3 | |
| }, | |
| { | |
| "x": 4, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 24.4 | |
| }, | |
| { | |
| "x": 4, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 22.8 | |
| }, | |
| { | |
| "x": 6, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 19.2 | |
| }, | |
| { | |
| "x": 6, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 17.8 | |
| }, | |
| { | |
| "x": 8, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 16.4 | |
| }, | |
| { | |
| "x": 8, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 17.3 | |
| }, | |
| { | |
| "x": 8, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 15.2 | |
| }, | |
| { | |
| "x": 8, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 10.4 | |
| }, | |
| { | |
| "x": 8, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 10.4 | |
| }, | |
| { | |
| "x": 8, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 14.7 | |
| }, | |
| { | |
| "x": 4, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 32.4 | |
| }, | |
| { | |
| "x": 4, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 30.4 | |
| }, | |
| { | |
| "x": 4, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 33.9 | |
| }, | |
| { | |
| "x": 4, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 21.5 | |
| }, | |
| { | |
| "x": 8, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 15.5 | |
| }, | |
| { | |
| "x": 8, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 15.2 | |
| }, | |
| { | |
| "x": 8, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 13.3 | |
| }, | |
| { | |
| "x": 8, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 19.2 | |
| }, | |
| { | |
| "x": 4, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 27.3 | |
| }, | |
| { | |
| "x": 4, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 26 | |
| }, | |
| { | |
| "x": 4, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 30.4 | |
| }, | |
| { | |
| "x": 8, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 15.8 | |
| }, | |
| { | |
| "x": 6, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 19.7 | |
| }, | |
| { | |
| "x": 8, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 15 | |
| }, | |
| { | |
| "x": 4, | |
| "y2": 0, | |
| "group": 1, | |
| "y": 21.4 | |
| } | |
| ] | |
| }, | |
| { | |
| "name": "stats", | |
| "source": "table", | |
| "transform": [ | |
| { | |
| "type": "aggregate", | |
| "groupby": [ | |
| "x" | |
| ], | |
| "summarize": { | |
| "y": ["min","max", "median", "q1", "q3", "valid"] | |
| } | |
| } | |
| ] | |
| }, | |
| { | |
| "name": "iqrcalcs", | |
| "source": "stats", | |
| "transform": [{"type": "formula", "field": "lower", "expr": "max(datum.min_y,datum.q1_y-1.5*(datum.q3_y-datum.q1_y))"}, | |
| {"type": "formula", "field": "upper", "expr": "min(datum.max_y,datum.q3_y+1.5*(datum.q3_y-datum.q1_y))"}] | |
| } | |
| ], | |
| "marks": [ | |
| { | |
| "properties": { | |
| "enter": { | |
| "height": { | |
| "value": 1 | |
| }, | |
| "x2": { | |
| "field": "upper", | |
| "scale": "x" | |
| }, | |
| "x": { | |
| "field": "lower", | |
| "scale": "x" | |
| }, | |
| "yc": { | |
| "field": "x", | |
| "scale": "y" | |
| }, | |
| "fill": { | |
| "value": "#888" | |
| } | |
| } | |
| }, | |
| "from": { | |
| "data": "iqrcalcs" | |
| }, | |
| "type": "rect" | |
| }, | |
| { | |
| "type": "rect", | |
| "from": {"data": "iqrcalcs"}, | |
| "properties": { | |
| "enter": { | |
| "x": {"scale": "x", "field": "q1_y"}, | |
| "x2": {"scale": "x", "field": "q3_y"}, | |
| "yc": {"scale": "y", "field": "x"}, | |
| "height": {"signal": "boxSize"}, | |
| "fill": {"value": "green"}, | |
| "stroke": {"value": "#888"} | |
| } | |
| } | |
| }, | |
| { | |
| "type": "rect", | |
| "from": {"data": "iqrcalcs"}, | |
| "properties": { | |
| "enter": { | |
| "x": {"scale": "x", "field": "median_y"}, | |
| "width": {"value": 2}, | |
| "yc": {"scale": "y", "field": "x"}, | |
| "height": {"signal": "boxSize"}, | |
| "fill": {"value": "#000"} | |
| } | |
| } | |
| }, | |
| { | |
| "type": "rect", | |
| "from": {"data": "iqrcalcs"}, | |
| "properties": { | |
| "enter": { | |
| "x": {"scale": "x", "field": "lower"}, | |
| "width": {"value": 1}, | |
| "yc": {"scale": "y", "field": "x"}, | |
| "height": {"signal": "boxSize", "mult": 0.5}, | |
| "fill": {"value": "#000"} | |
| } | |
| } | |
| }, | |
| { | |
| "type": "rect", | |
| "from": {"data": "iqrcalcs"}, | |
| "properties": { | |
| "enter": { | |
| "x": {"scale": "x", "field": "upper"}, | |
| "width": {"value": 1}, | |
| "yc": {"scale": "y", "field": "x"}, | |
| "height": {"signal": "boxSize", "mult": 0.5}, | |
| "fill": {"value": "#000"} | |
| } | |
| } | |
| }, | |
| { | |
| "type": "symbol", | |
| "from": {"data": "stats"}, | |
| "properties": { | |
| "enter": { | |
| "x": {"scale": "x", "field": "min_y"}, | |
| "yc": {"scale": "y", "field": "x"}, | |
| "size": {"value": 20}, | |
| "stroke": {"value": "#000"}, | |
| "fill": {"value": "#fff"} | |
| } | |
| } | |
| }, | |
| { | |
| "type": "symbol", | |
| "from": {"data": "stats"}, | |
| "properties": { | |
| "enter": { | |
| "x": {"scale": "x", "field": "max_y"}, | |
| "yc": {"scale": "y", "field": "x"}, | |
| "size": {"value": 20}, | |
| "stroke": {"value": "#000"}, | |
| "fill": {"value": "#fff"} | |
| } | |
| } | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment