Hi! Can I use AlgebraOfGraphics to create a violin plot, overlay a boxplot with some transparency and also to be able to see all the dots?
Thanks for your help!
Hi! Can I use AlgebraOfGraphics to create a violin plot, overlay a boxplot with some transparency and also to be able to see all the dots?
Thanks for your help!
So I’ll walk through how I found the info and I’ll give a rough shell on a solution . I don’t have the ability to test it right now, so my solution won’t be copy paste workable, and there may be better solutions, but here is one. AlgebraOfGraphics has a tutorial set. In the first one there is a section called “stacking layers with +”. There is also “Attributes of visual” that links to the Makie documentation describing the attributes available for its different plotting sections. From that we can say you want the Violin Scatter and Boxplot visuals.
I looked at the boxplot documentation for transparency stuff and there was no “alpha” or “transparency” attribute. I just looked up “Makie.jl transparent fill boxplot” and got this page. This seems to say that you can use RGBA colors. So if you create a set of RGB colors, you can then set your mapping variable to those, and then when you create the boxplot layer, you can do some sort of mapping from your color variable to RGBA with a set alpha.
So you’ll have something like this
m = data(df) * mapping(:x,:y, color=:csvar)
violinp = m * visual(Violin)
boxplotp = m * mapping(:x, :y, color= :csvar => (c -> RGBA(c,0.4))) *visual(Boxplot)
scatterp = m * visual(Scatter)
draw(violinp + boxplotp + scatterp)
There are jittering/beeswarm ways of performing the scatterplot if you want.
The data viz person in me also has to cordially ask, do you need the boxplot, and does the violin tell a violin specific story? Or could just a beeswarm show the same info? That could make this plotting solution much simpler (one simple layer rather than three, potentially complicated layers). But it’s not my place to assert plotting decisions, we don’t need to discuss this point more, I just wanted to float the idea.
Yeah in principle that would be just three visuals like visual(Violin) + visual(Boxplot, alpha = 0.5) + visual(Beeswarm, algorithm = :quasirandom) with Beeswarm from the 0.2 branch of SwarmMakie.jl (not merged and released, yet).
But I also think I recently noticed box plot doesn’t respect alpha, yet, so that might need fixing first