GiovineItalia / Gadfly.jl

Crafty statistical graphics for Julia.
http://gadflyjl.org/stable/
Other
1.9k stars 250 forks source link

Add dodging to violin plots that call :color #1635

Open hbsmith opened 6 days ago

hbsmith commented 6 days ago

I'm trying to make violin plot versions of the boxplots which are displayed as p2 here: https://gadflyjl.org/stable/gallery/geometries/#[Geom.boxplot](@ref)

image

My expectation is that :color in a violin plot would would like it does in a boxplot, but it does not. If I want to plot two different categories using a violin plot, where both categories have the same x-axis, it does not work. I'd expect it to apply dodge to the datasets. After digging, it seems like there is no option to even have violin plot dodge.

Basically, I want to make the same kind of plot that seaborn demonstrates here: https://seaborn.pydata.org/generated/seaborn.violinplot.html sns.violinplot(data=df, x="class", y="age", hue="alive") image

Is there a way to do this that I'm not aware of?

Mattriks commented 5 days ago

Yes the dodge effect isn't implemented yet for Geom.violin, and we're happy to see PRs! A possible workaound is:

plot(salaries, x=:Rank, y=:Salary, color=:Rank,
    xgroup=:Discipline,
    Geom.subplot_grid(Geom.violin),
    Scale.xgroup(levels=["Discipline A", "Discipline B"]),
    Guide.xlabel(nothing)
)