question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

grouped bar charts (Faceted or VConcat)?

See original GitHub issue

I’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: image

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: image

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:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
domoritzcommented, Jul 2, 2018
1reaction
domoritzcommented, Jul 2, 2018

We’re going to fix this in Vega-Lite. It will be included in the next release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Compound Charts: Layer, HConcat, VConcat, Repeat, Facet
The Chart.repeat() method is the key here: it lets you specify a set of encodings for the row and/or column which can be...
Read more >
GGPLOT grouped bar plot with facets: multiple aligned labels ...
I am trying to get my bar plot to look a certain way. I hope you can follow me without really explaining what...
Read more >
Multi-View Composition - Nextjournal
Faceting involves subdividing a dataset into groups and creating a separate plot for each group. In earlier notebooks, we learned how to ...
Read more >
Example Gallery — Altair 4.1.0 documentation
Other Charts¶. Bar Chart with Highlighted Segment Becker's Barley Trellis Plot (wrapped facet) Binned Heatmap ...
Read more >
Altair Limit Number Of Bars In Facet Chart - ADocLib
Highlight columns B to D. Really all we need to do is plot a set of bar charts ... visualization with altair practical...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found