sort channel not working when I add text on top of my bars
See original GitHub issueThis sorts like I want.
import altair as alt
from vega_datasets import data
barley = data.barley()
alt.Chart(cars.head(10)).mark_bar().encode(
x='Miles_per_Gallon:Q',
y=alt.Y('Name:N', sort=alt.SortField(field="Miles_per_Gallon", op="sum", order="descending"))
)
This does not.
bars = alt.Chart(cars.head(10)).mark_bar().encode(
x='Miles_per_Gallon:Q',
y=alt.Y('Name:N', sort=alt.SortField(field="Miles_per_Gallon", op="sum", order="descending"))
)
text = bars.mark_text(
align='left',
baseline='middle',
dx=3,
).encode(text='Miles_per_Gallon:Q')
bars + text
Why?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:17 (9 by maintainers)
Top Results From Across the Web
Order bar chart in Altair? - python - Stack Overflow
The sort keyword needs to be applied to the axis being sorted - here it's ... Simple alternative, specify the channel you'd like...
Read more >Adjust your sidebar preferences - Slack
Sort your conversations · From your desktop, click your profile picture in the top right. · Select Preferences from the menu. · Click...
Read more >How to Sort Your Bar Charts - Depict Data Studio
Option B: Re-Sort the Bars within the Chart · Click on the category labels on the left. · Hold your mouse over the...
Read more >Sort and arrange items in the Finder on Mac - Apple Support
The top of a Finder window showing View option buttons for a folder. Your settings for sorting and arranging items in a folder...
Read more >Order Bars of ggplot2 Barchart in R (4 Examples)
Thank you for the comment. I think the reason for this is the last line of your code (i.e. '+ guides(fill = FALSE)')....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m not sure why this is happening; I think it’s a vega-lite bug. Here’s a simplified vega-lite spec showing the issue (Open the Chart in the Vega Editor):
If you delete the
filter
line, the sort works as expected.I think it’s probably some issue with unioned domains, though strangely there is no warning in the Vega editor.
As a workaround, you can set
resolve_scale(y='independent')
, which preserves the sort:The default aggregation is set within Vega-Lite. It might be worth a feature request there.