Recommended way to move headers to the bottom of subplots for grouped bar charts

1.1k Views Asked by At

I am trying to make a chart like the following in VL/Altair:

enter image description here

In this example, the X axis labels function like VL headers as far as I can tell. In VL/Altair, the headers are automatically set to the top of each subplot (e.g., this chart).

What is the recommended way of creating a grouped bar chart like this where the headers are located at the bottom?

If I work from this VL example, I can use "labelPadding" to move the headers down below but would like to know if there is a better way of accomplishing this without hard coded values (I've tried other options from the header docs but it seems that headers really prefer to be above the subplots, unless I've missed something):

"column": {"type": "nominal", "field": "site", "header": {"labelPadding": -320}}
1

There are 1 best solutions below

3
On

You can set the location of the header title and labels using labelOrient and titleOrient properties of the column's header.

Modifying the grouped bar chart example you linked to, it might look something like this:

import altair as alt
from vega_datasets import data

source = data.barley()

alt.Chart(source).mark_bar().encode(
    x=alt.X('year:O',
        axis=alt.Axis(title=None, labels=False)),
    y='sum(yield):Q',
    color='year:N',
    column=alt.Column('site:N',
        header=alt.Header(titleOrient='bottom', labelOrient='bottom'))
)

enter image description here