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

**URL:** <https://discourse.julialang.org/t/how-can-i-plot-violin-plots-at-specific-x-axis-labels-if-my-data-is-not-in-a-dataframe/44544>\
**Category:** Visualization\
**Created:** [August 8, 2020, 2:58am UTC](https://discourse.julialang.org/t/how-can-i-plot-violin-plots-at-specific-x-axis-labels-if-my-data-is-not-in-a-dataframe/44544 "2020-08-08T02:58:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pjentsch0](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pjentsch0/32/15148_2.png) [@pjentsch0](https://discourse.julialang.org/u/pjentsch0)\
**Post date:** [August 8, 2020, 2:58am UTC](https://discourse.julialang.org/t/how-can-i-plot-violin-plots-at-specific-x-axis-labels-if-my-data-is-not-in-a-dataframe/44544/1 "2020-08-08T02:58:43Z")

</div>

For instance, the following code makes this figure:

 ![example](https://global.discourse-cdn.com/julialang/original/3X/e/e/ee32b5e8180507e8a2a37a55d9a0866f512ec7e4.png)

```julia
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:

 ![example2](https://global.discourse-cdn.com/julialang/original/3X/d/3/d33c3bf406a3056a46ee393c0b6bc825f5832aca.png).

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

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [August 8, 2020, 8:12am UTC](https://discourse.julialang.org/t/how-can-i-plot-violin-plots-at-specific-x-axis-labels-if-my-data-is-not-in-a-dataframe/44544/2 "2020-08-08T08:12:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pjentsch0](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pjentsch0/32/15148_2.png) [@pjentsch0](https://discourse.julialang.org/u/pjentsch0)\
**Post date:** [August 8, 2020, 4:24pm UTC](https://discourse.julialang.org/t/how-can-i-plot-violin-plots-at-specific-x-axis-labels-if-my-data-is-not-in-a-dataframe/44544/3 "2020-08-08T16:24:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [August 8, 2020, 4:39pm UTC](https://discourse.julialang.org/t/how-can-i-plot-violin-plots-at-specific-x-axis-labels-if-my-data-is-not-in-a-dataframe/44544/4 "2020-08-08T16:39:48Z")

</div>

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

```julia
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

```julia
@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

```julia
violin(x, y)

```

should do what you want.

---

<div class="post-metadata">

**Author:** ![pjentsch0](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pjentsch0/32/15148_2.png) [@pjentsch0](https://discourse.julialang.org/u/pjentsch0)\
**Post date:** [August 8, 2020, 5:04pm UTC](https://discourse.julialang.org/t/how-can-i-plot-violin-plots-at-specific-x-axis-labels-if-my-data-is-not-in-a-dataframe/44544/5 "2020-08-08T17:04:55Z")

</div>

edit: I misunderstood your answer, sorry!

`
