Search code examples
plotjuliaviolin-plotstatsplots.jl

Swap Axes of Violin plot


I am trying to create Violin Plots using the StatsPlots.jl library. However, I would like to have the returned Violin plot to be horizontal instead of vertical as I want to show the distribution of a variable (e.g. Temperature) for different heights, eg. at 1000m, 2000m, 3000m ...

So it would be nice if the height was at the y-Axis while the temperature distribution was on the x-Axis. Is there a way to swap the axes of a Plots.Plot struct, or is there an argument I could pass to violin() that does the trick?


Solution

  • It seems the permute keyword is documented for other plots (see Plots API) and it works for me with violin (StatsPlots v0.15.7). Here's the syntax:

    violin(
           repeat([1,2,3], outer=100),
           randn(300),
           permute = (:y, :x)
    )