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.

How to reverse the sort order of stacked bars

See original GitHub issue

Here’s my draft chart.

alt.Chart(latino_chart_prepped, title="Latino share of U.S. population").mark_bar().encode(
    alt.X('age:O', axis=alt.Axis(title="Age"), sort=alt.SortField(field="sort", op="sum", order="ascending")),
    alt.Y('population:Q',
        axis=alt.Axis(title='Percent of population'),
        stack='normalize'
    ),
    alt.Color('group:N', legend=None)
).properties(
    width=600
)

visualization 2

How do I reverse the sort order so that the smaller blue bars are on the bottom of each stack in the chart?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jakevdpcommented, Apr 1, 2018

Nope, I’m still working on getting things like that in the docs. It’s a long process.

Some examples would be useful… we also need an actual in-depth discussion of all the encodings that are available and what they are good for.

1reaction
jakevdpcommented, Mar 31, 2018

Add an order channel:

alt.Chart(...).encode(
    ...
    order=alt.Order('group', sort='ascending')
    ...
)

You may need to use sort='descending' instead… without seeing your data, it’s difficult to guess.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reversing the order of stacked bar chart - Tableau Community
Right click on Color Mark of Audit Failur and select Descending... Have tried replicating with Sample super store data source. Let me know...
Read more >
Solved: Reverse order in Stacked Column Chart
Reverse order in Stacked Column Chart · 1. Create a proper order column if you don't have one. · 2. Change the sort...
Read more >
Stacked Bar Chart columns are in reverse order
If you want the A series to be stacked at the top, you just need to re-arrange the order of the data in...
Read more >
Change the plotting order of categories, values, or data series
Reverse the plotting order of categories or values in a chart · For categories, select the Categories in reverse order check box. ·...
Read more >
Reverse stacked bar order - Stack Overflow
position_fill(reverse = TRUE) normalizes bars, use position_stack(reverse = TRUE) if you don't want to normalize bars. – mihagazvoda. Sep 10, ...
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