Created
April 5, 2019 21:18
-
-
Save AlexAbes/c17703ce10f7f4a272324ea317e7afce to your computer and use it in GitHub Desktop.
Converted the Vega example grouped horizontal bar chart into a vertical one. https://vega.github.io/vega/examples/grouped-bar-chart/
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/v5.json", | |
| "width": 450, | |
| "height": 350, | |
| "padding": 5, | |
| "data": [ | |
| { | |
| "name": "table", | |
| "values": [ | |
| {"category":"A", "position":0, "value":0.1}, | |
| {"category":"A", "position":1, "value":0.6}, | |
| {"category":"A", "position":2, "value":0.9}, | |
| {"category":"A", "position":3, "value":0.4}, | |
| {"category":"B", "position":0, "value":0.7}, | |
| {"category":"B", "position":1, "value":0.2}, | |
| {"category":"B", "position":2, "value":1.1}, | |
| {"category":"B", "position":3, "value":0.8}, | |
| {"category":"C", "position":0, "value":0.6}, | |
| {"category":"C", "position":1, "value":0.1}, | |
| {"category":"C", "position":2, "value":0.2}, | |
| {"category":"C", "position":3, "value":0.7} | |
| ] | |
| } | |
| ], | |
| "scales": [ | |
| { | |
| "name": "xscale", | |
| "type": "band", | |
| "domain": {"data": "table", "field": "category"}, | |
| "range": "width", | |
| "padding": 0.2 | |
| }, | |
| { | |
| "name": "yscale", | |
| "type": "linear", | |
| "domain": {"data": "table", "field": "value"}, | |
| "range": "height", | |
| "round": true, | |
| "zero": true, | |
| "nice": true | |
| }, | |
| { | |
| "name": "color", | |
| "type": "ordinal", | |
| "domain": {"data": "table", "field": "position"}, | |
| "range": {"scheme": "category20"} | |
| } | |
| ], | |
| "axes": [ | |
| {"orient": "bottom", "scale": "xscale", "tickSize": 0, "labelPadding": 4, "zindex": 1}, | |
| {"orient": "left", "scale": "yscale"} | |
| ], | |
| "marks": [ | |
| { | |
| "type": "group", | |
| "from": { | |
| "facet": { | |
| "data": "table", | |
| "name": "facet", | |
| "groupby": "category" | |
| } | |
| }, | |
| "encode": { | |
| "enter": { | |
| "x": {"scale": "xscale", "field": "category"} | |
| } | |
| }, | |
| "signals": [ | |
| {"name": "width", "update": "bandwidth('xscale')"} | |
| ], | |
| "scales": [ | |
| { | |
| "name": "pos", | |
| "type": "band", | |
| "range": "width", | |
| "domain": {"data": "facet", "field": "position"} | |
| } | |
| ], | |
| "marks": [ | |
| { | |
| "name": "bars", | |
| "from": {"data": "facet"}, | |
| "type": "rect", | |
| "encode": { | |
| "enter": { | |
| "x": {"scale": "pos", "field": "position"}, | |
| "width": {"scale": "pos", "band": 1}, | |
| "y": {"scale": "yscale", "field": "value"}, | |
| "y2": {"scale": "yscale", "value": 0}, | |
| "fill": {"scale": "color", "field": "position"} | |
| } | |
| } | |
| }, | |
| { | |
| "type": "text", | |
| "from": {"data": "bars"}, | |
| "encode": { | |
| "enter": { | |
| "x": {"field": "x", "offset": {"field": "width", "mult": 0.75}}, | |
| "y": {"field": "y", "offset": 10}, | |
| "fill": {"value": "white"}, | |
| "align": {"value": "right"}, | |
| "baseline": {"value": "middle"}, | |
| "text": {"field": "datum.value"} | |
| } | |
| } | |
| } | |
| ] | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment