Any way to sort two layers together?
See original GitHub issueI have a sorted mark_bar()
and would like to add a layer of mark_tick
or top of this, while preserving the sorted order.
This sorting works:
from vega_datasets import data
df = data.movies()
df['WW_Margin'] = (df['Worldwide_Gross'] - df['Production_Budget']) / 1e6
lower_box = 'q1(WW_Margin):Q'
upper_box = 'q3(WW_Margin):Q'
bar_plot = alt.Chart(df).mark_bar(size=5.0).encode(
alt.X('Major_Genre:O',
# sort=alt.SortField(field='WW_Margin', op='median',
# order='descending')
),
y=lower_box,
y2=upper_box,
)
median_tick = bar_plot.mark_tick(
color='white',
size=5.0
).encode(
y='median(WW_Margin):Q',
)
bar_plot
But when I add a mark_tick layer, the sorting or the bars is gone, and it reverts to alphabetical sorting.
from vega_datasets import data
df = data.movies()
df['WW_Margin'] = (df['Worldwide_Gross'] - df['Production_Budget']) / 1e6
lower_box = 'q1(WW_Margin):Q'
upper_box = 'q3(WW_Margin):Q'
bar_plot = alt.Chart(df).mark_bar(size=5.0).encode(
alt.X('Major_Genre:O',
sort=alt.SortField(field='WW_Margin', op='median',
order='descending')
),
y=lower_box,
y2=upper_box,
)
median_tick = bar_plot.mark_tick(
color='white',
size=5.0
).encode(
y='median(WW_Margin):Q',
)
bar_plot + median_tick #note below that sorting is gone
This is quite possibly related to #698 which in turn refers to a Vega-lite issue(vega/vega-lite#2177). Will this get resolved when a newer version of Vega-lite is incorporated into Altair? Thanks much.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
How to do Multiple Level Data Sorting in Excel
This technique works the same way with a minor difference – you sort the second level first and then move to the first...
Read more >How to Do Multi level sorting in Excel (by two Columns)
In this video, I'll show you how to do a multi- level sorting in Excel. This means that you sort data by 2...
Read more >How to sort data by multiple columns in Excel
Click Add Level, choose Region from the Then By dropdown (Figure C), and click OK to execute the sort.
Read more >Sort data in a table
Custom Sort - sorts data in multiple columns by applying different sort criteria. Here's how to do a custom sort: Select Custom Sort....
Read more >How to Perform Multi-Level Data Sorting in Excel?
Step 4: In the Sort box one row of Level is inbuilt by Excel so, click two times on Add Level to add...
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
The order of the axis and the order in which the points are connected are distinct concepts. If you want to change the order in which the points are connected, you can use the
order
channel. Details in the docs here: https://altair-viz.github.io/user_guide/encoding.html#ordering-marksAlso, ordering of axis for layered charts based on different datasets is still not supported (open the javascript console and you’ll see the relevant warnings output by Vega-Lite). You’ll need to source both charts from the same dataset if you want the orders to be propagated to the layered chart.