How can I plot violin plots at specific x-axis labels if my data is not in a dataframe?

For instance, the following code makes this figure:

julia> d = Normal()
julia> a = rand(d,10,1000)
julia> violin(collect(eachrow(a)),legend = false)

If I have a vector of 10 x-axis points, say x_pts = 1:10:100, then the command violin(map(x-> "x = $x", x_pts),collect(eachrow(a)),legend = false) gives the following figure:


For some reason, all of the StatsPlots documentation assumes the data is in a dataframe. Is this possible to do without that?

The examples using a data frame (with the @df macro) also work with regular code if you pass vectors of values instead of symbols corresponding to the DataFrame columns.

1 Like

Could you give an example of this in the context of what I posted?

It seems I still need to have a DataFrame to use as the first argument to the @df macro.

If you do not have a DataFrame, but just some vectors, you should skip the @df macro altogether.

For example, let’s say your data is

x = rand(["a", "b", "c"], 100)
y = rand(100)

The DataFrame case (let’s say df = DataFrame(col1 = x, col2 = y)) would be handled as

@df df violin(:col1, :col2)

What the macro does, under the hood, is to replace those symbols with the respective columns (df.col1, df.col2). This is not necessary if you have easy access to the vectors, and just

violin(x, y)

should do what you want.

edit: I misunderstood your answer, sorry!