Hi
I want to present some data to a colleague, whilst also showing off Julia. I have data for an effect that varies according to species and treatment. There are 2 treatments and I would like to display effect sizes as pairs of violin plots, a single pair for each species, coloured according to treatment, all in the same plotting area.
Additionally, I want to share the code that generated the plots, so it would be great to be able to produce something that looks nice and has an appropriate legend etc. with few lines of code.
The code below produces something decent enough (not “publication quality” which is obviously in the eye of the beholder anyway!). But the violins for each species, the 2 violins are stacked on top of eachother, making it difficult to interpret. Incidentally I’m getting a “Canvas Renderer is missing” error when I try to save the output, so I cant display the plot here.
using VegaLite,DataFrames
mydf = DataFrame([rand(["a","b","c"],1000),rand(["x1","x2"],1000),rand(1000)])
names!(mydf,[:species,:treatment,:value])
mydf |> @vlplot(
mark={:area, orient="horizontal"},
transform=[
{density="value", groupby=["treatment","species"],
as=[ "value", "density"]}
],
y="value:q",
x= {"density:q", impute=nothing,stack = "center", title=nothing,
axis={ values=[], grid=false, ticks=true}},
color = "treatment:n",
width=70,
spacing=0,
column = :species,
config={view={stroke=nothing}}
)
I’m not tied to using VegaLite. But I started using it recently, as it seemed to be the most straightforward package for creating faceted plots from dataframes. This is useful for me in data exploration, but also something my colleagues who all use R would feel at home with.