yippingAppa
yippingAppa

Reputation: 561

Altair: Customizing outliers in boxplots

Is there any way to customize the outlier points in an Altair boxplot? Suppose I had the following plot:

penguins_data="https://raw.githubusercontent.com/datavizpyr/data/master/palmer_penguin_species.tsv"
penguins_df = pd.read_csv(penguins_data, sep="\t")
chart = alt.Chart(penguins_df).mark_boxplot(size=50, extent=0.5).encode(
    x='species:O',
    y=alt.Y('culmen_length_mm:Q',scale=alt.Scale(zero=False)),
    color=alt.Color('species')
).properties(width=300)

penguin boxplot

I would like to jitter the outliers and also make the points smaller. Is that possible, or would we have to create two layered plots? Ideally the jittered points are all found within the width of the boxplot itself, but that isn't necessary.

Upvotes: 1

Views: 1230

Answers (1)

joelostblom
joelostblom

Reputation: 48929

I don't think you can jitter them, but you can make them smaller:

alt.Chart(penguins_df).mark_boxplot(size=50, extent=0.5, outliers={'size': 5}).encode(
    x='species:O',
    y=alt.Y('culmen_length_mm:Q',scale=alt.Scale(zero=False)),
    color=alt.Color('species')
    
).properties(width=300)

enter image description here

Upvotes: 4

Related Questions