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.

Boxplots with filter transform based on selection don't work

See original GitHub issue

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

image

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

image

Is this an issue with Altair, or with vega-lite?

Thanks for your help!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
joelostblomcommented, Feb 23, 2021

@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.

1reaction
carusovcommented, Aug 18, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

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