Apologies if this has been asked before, but I'm looking for a way to create bar-charts that are "dodged" (language from ggplot2
) using the Altair library in python.
I know Altair has this example:
import altair as alt
from vega_datasets import data
source = data.barley()
alt.Chart(source).mark_bar().encode(
x='year:O',
y='sum(yield):Q',
color='year:N',
column='site:N'
)
That produces this plot:
However, this has a lot of redundant labels and information. Ideally I want a plot where the paired bars encode the year in colour (blue is 1931 and orange is 1932) and then the cities running along the x-axis (ordinal variable).
Hard to explain, but here's an example of how to get a plot like this from seaborn (using different data; source isthis SO question):