This is actually possible within Vega 5.0, legend layout property, by setting the anchor
property to "middle"
, in the legend's layout config.
Providing layout
doesn't seem to be directly supported by Vega-Lite yet, but it is possible to propagate a layout
definition from Vega-Lite to Vega.
Following Jake's answer, in Vega-Lite editor:
{
"data": {"url": "data/cars.json"},
"mark": "point",
"encoding": {
"x": {"field": "Horsepower", "type": "quantitative"},
"y": {"field": "Miles_per_Gallon", "type": "quantitative"},
"color": {"field": "Origin", "type": "nominal"}
},
"height": 300,
"width": 400,
"config": {
"legend": {"orient": "bottom", "layout": {"bottom": {"anchor": "middle"}}}
}
}
Specifying the config
at the end basically allows you to customize how the orient
"bottom"
should look.
layout: { bottom: { anchor: "middle" } } as LegendLayout as any,
just in-case people wander here with Typescript/React in mind – Lanie