grouped bar charts (Faceted or VConcat)?
See original GitHub issueI’m trying to do something like this example, but repeated across a separate dimension. I’d like to have a shared y-axis within each grouped bar chart, but I’d like to have an independent y-axis across different bar charts. (Hopefully that makes sense).
I can get something to render if I just add facets, but it will share the y-axis within each chart as well as across different charts is undesirable and ends up looking like this:
If I set resolve_scale(y='independent')
, it ends up decoupling the y-axis within each chart as well as across different charts which is also undesirable:
If I try to vconcat each independent grouped bar chart, it complains that my vconcat is invalid.
Any ideas on how to accomplish what I want?
I tried to repurpose the example code to use it as example code, and it fails. Hopefully this helps explain what I’m trying to do.
My code
import altair as alt
from altair.expr import datum, if_
from vega_datasets import data
source = data.population.url
base = alt.Chart(source).mark_bar(stroke='transparent').encode(
alt.X('gender:N', scale=alt.Scale(rangeStep=12), axis=alt.Axis(title='')),
alt.Y('sum(people):Q', axis=alt.Axis(title='population', grid=False)),
color=alt.Color('gender:N', scale=alt.Scale(range=["#EA98D2", "#659CCA"])),
column='age:O'
# comment out configure functions that can't be used in a vconcat
# ).configure_view(
# stroke='transparent'
# ).configure_axis(
# domainWidth=0.8
).transform_filter(
datum.year == 2000
).transform_calculate(
'gender', if_(datum.sex == 2, 'Female', 'Male')
)
chart = alt.vconcat()
chart &= base
chart
The error
Invalid specification
altair.vegalite.v2.api.VConcatChart->vconcat->items, validating 'anyOf' {'data': {'url': 'https://vega.github.io/vega-datasets/data/population.json'}, 'mark': {'type': 'bar', 'stroke': 'transparent'}, 'encoding': {'color': {'type': 'nominal', 'field': 'gender', 'scale': {'range': ['#EA98D2', '#659CCA']}}, 'column': {'type': 'ordinal', 'field': 'age'}, 'x': {'type': 'nominal', 'axis': {'title': ''}, 'field': 'gender', 'scale': {'rangeStep': 12}}, 'y': {'type': 'quantitative', 'aggregate': 'sum', 'axis': {'grid': False, 'title': 'population'}, 'field': 'people'}}, 'transform': [{'filter': '(datum.year === 2000)'}, {'calculate': "if((datum.sex === 2),'Female','Male')", 'as': 'gender'}]} is not valid under any of the given schemas
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
Fixed in https://github.com/vega/vega-lite/pull/3965
We’re going to fix this in Vega-Lite. It will be included in the next release.