-
|
I'm trying to separate business and economy class but for some reason I can't make it as grouped bar chart? import polars as pl
import altair as alt
df = pl.read_csv('data.csv')
c1 = alt.Chart(
data = df.with_columns(
(pl.col('price') / pl.col('duration')).alias('price_per_hour')
),
title = 'Most Expensive Airlines'
).mark_bar().encode(
x = alt.X('price_per_hour', aggregate = 'average', title = 'Average price per hour'),
y = alt.Y('airline', sort = '-x'),
color = 'class'
)
c1
I followed the gallery example but the difference is I don't need to use the |
Beta Was this translation helpful? Give feedback.
Answered by
mattijn
Feb 13, 2026
Replies: 1 comment 1 reply
-
|
Maybe using a row encoding channel? See https://altair-viz.github.io/gallery/grouped_bar_chart_horizontal.html Or yOffset encoding channel, see example using xOffset: https://altair-viz.github.io/gallery/grouped_bar_chart2.html |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
AndhikaWB
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Maybe using a row encoding channel? See https://altair-viz.github.io/gallery/grouped_bar_chart_horizontal.html
Or yOffset encoding channel, see example using xOffset: https://altair-viz.github.io/gallery/grouped_bar_chart2.html