Boxplots with filter transform based on selection don't work
See original GitHub issueI’m have a series of metrics that I’ve computed for different sample groups in my data, and I want to compare the distributions of a given metric with a boxplot for each sample group, using a dropdown list to choose the metric being compared. But when I do the following, I get a JavaScript Error:
import altair as alt, pandas as pd
import numpy as np
np.random.seed(431)
metrics = pd.DataFrame({
'metric1': np.random.normal(30, 20, 100),
'metric2': np.random.lognormal(2, 1, 100),
'metric3': np.random.uniform(0, 80, 100),
'group': np.random.choice(['A', 'B'], 100)
})
metrics = pd.melt(
metrics,
id_vars='group',
var_name='metric',
value_name='value'
)
group_dropdown = alt.binding_select(options=['metric1', 'metric2', 'metric3'])
group_selection = alt.selection_single(
fields=['metric'],
bind=group_dropdown,
name='Group ',
init={'metric': 'metric1'}
)
distribution_boxes = alt.Chart(metrics).mark_boxplot(size=30).encode(
x='group',
y=alt.Y('value', title='metric1'),
color='group',
).properties(
width=150,
height=300
).transform_filter(
group_selection
).add_selection(
group_selection
)
distribution_boxes
When I change the mark type to mark_tick()
, the plot renders correctly:
distribution_ticks = alt.Chart(metrics).mark_tick(size=30).encode(
x='group',
y=alt.Y('value', title='metric1'),
color='group',
).properties(
width=150,
height=300
).transform_filter(
group_selection
).add_selection(
group_selection
)
distribution_ticks
Is this an issue with Altair, or with vega-lite?
Thanks for your help!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Filter selection is not working properly in some box plots
Filter selection is not working properly in some box plots. I have a project where the filtering on some box plots work properly...
Read more >Box Plot | Vega-Lite
A box plot summarizes a distribution of quantitative values using a set of summary statistics. The median tick in the box represents the...
Read more >boxplot() in R: How to Make BoxPlots in RStudio [Examples]
Step 1: Import the data; Step 2: Drop unnecessary variables; Step 3: Convert Month in factor level; Step 4: Create a new categorical...
Read more >BOXPLOT in R [boxplot by GROUP, MULTIPLE box plot, ...]
The input of the ggplot library has to be a data frame, so you will need convert the vector to data.frame class. Then,...
Read more >pandas.DataFrame.boxplot — pandas 1.5.2 documentation
A box plot is a method for graphically depicting groups of numerical data through ... When return_type='axes' is selected, the matplotlib axes on...
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
@carusov This is being tracked in https://github.com/vega/vega-lite/issues/3702 and can become available in Altair after it is implemented in Vega-Lite.
Hi @baogianghoangvu, thanks for looking into this. I figured it probably wasn’t implemented in vega-lite yet, but I don’t know much about JS and I didn’t think to check the browser console- I’ll remember that next time I have an issue.
Your suggestion to use the column channel is a good one, but in my actual use case I have another variable that I’m faceting via columns. I guess I could use the row channel too, but I was trying to keep the chart from getting too busy.