I know how to make a horizontal, stacked, normalized bar in Vega, but I can't figure out what the best way to create the offset. What the original block author did was split the middle group in half, but I can't quite figure out how to express this in Vega. Any help would be greatly appreciated!
{
"name": "Vega Visualization",
"height": 450,
"padding": "auto",
"marks": [
{
"properties": {
"enter": {
"height": {"offset": -1,"scale": "x","band": true},
"x2": {"field": "layout_end","scale": "y"},
"x": {"field": "layout_start","scale": "y"},
"width": {"scale": "x","band": true},
"fill": {"field": "group","scale": "group"},
"y": {"field": "x","scale": "x"}
}
},
"from": {
"data": "table_uquz4",
"transform": [
{
"sortby": ["group"],
"offset": "normalize",
"field": "y",
"groupby": ["x"],
"type": "stack"
}
]
},
"type": "rect"
}
],
"axes": [
{
"layer": "front",
"properties": {"title": {"fontSize": {"value": 14}}},
"title": "y",
"grid": false,
"type": "x",
"scale": "y"
},
{
"layer": "front",
"properties": {"title": {"fontSize": {"value": 14}}},
"title": "x",
"grid": false,
"type": "y",
"scale": "x"
}
],
"data": [
{
"name": "table_uquz4",
"values": [
{"x": 1,"y2": 0,"group": 1,"y": 24},
{"x": 2,"y2": 0,"group": 2,"y": 2},
{"x": 3,"y2": 0,"group": 3,"y": 2},
{"x": 4,"y2": 0,"group": 4,"y": 0},
{"x": 5,"y2": 0,"group": 5,"y": 0},
{"x": 6,"y2": 0,"group": 1,"y": 2},
{"x": 7,"y2": 0,"group": 2,"y": 0},
{"x": 8,"y2": 0,"group": 3,"y": 0},
{"x": 1,"y2": 0,"group": 4,"y": 294},
{"x": 2,"y2": 0,"group": 5,"y": 2},
{"x": 3,"y2": 0,"group": 1,"y": 0},
{"x": 4,"y2": 0,"group": 2,"y": 2},
{"x": 5,"y2": 0,"group": 3,"y": 1},
{"x": 6,"y2": 0,"group": 4,"y": 1},
{"x": 7,"y2": 0,"group": 5,"y": 0},
{"x": 8,"y2": 0,"group": 1,"y": 0},
{"x": 1,"y2": 0,"group": 2,"y": 594},
{"x": 2,"y2": 0,"group": 3,"y": 0},
{"x": 3,"y2": 0,"group": 4,"y": 2},
{"x": 4,"y2": 0,"group": 5,"y": 1},
{"x": 5,"y2": 0,"group": 1,"y": 3},
{"x": 6,"y2": 0,"group": 2,"y": 2},
{"x": 7,"y2": 0,"group": 3,"y": 1},
{"x": 8,"y2": 0,"group": 4,"y": 0},
{"x": 1,"y2": 0,"group": 5,"y": 1927},
{"x": 2,"y2": 0,"group": 1,"y": 7},
{"x": 3,"y2": 0,"group": 2,"y": 4},
{"x": 4,"y2": 0,"group": 3,"y": 7},
{"x": 5,"y2": 0,"group": 4,"y": 16},
{"x": 6,"y2": 0,"group": 5,"y": 9},
{"x": 7,"y2": 0,"group": 1,"y": 4},
{"x": 8,"y2": 0,"group": 2,"y": 0},
{"x": 1,"y2": 0,"group": 3,"y": 376},
{"x": 2,"y2": 0,"group": 4,"y": 0},
{"x": 3,"y2": 0,"group": 5,"y": 2},
{"x": 4,"y2": 0,"group": 1,"y": 6},
{"x": 5,"y2": 0,"group": 2,"y": 4},
{"x": 6,"y2": 0,"group": 3,"y": 3},
{"x": 7,"y2": 0,"group": 4,"y": 0},
{"x": 8,"y2": 0,"group": 5,"y": 2}
]
},
{
"name": "stats",
"source": "table_uquz4",
"transform": [
{
"groupby": ["x"],
"type": "aggregate",
"summarize": [{"ops": ["sum"],"field": "y"}]
}
]
}
],
"scales": [
{
"name": "x",
"range": "height",
"domain": {"sort": true,"data": "table_uquz4","field": "x"},
"type": "ordinal"
},
{
"reverse": false,
"name": "y",
"zero": true,
"domainMax": 1,
"domain": {"data": "stats","field": "sum_y"},
"range": "width",
"type": "linear",
"round": false
},
{
"name": "group",
"range": ["#c7001e","#f6a580","#cccccc","#92c6db","#086fad"],
"domain": {"data": "table_uquz4","field": "group"},
"type": "ordinal"
}
],
"width": 450,
"legends": [{"title": "Group","fill": "group"}]
}