# Positioning in violin plot

**URL:** https://discourse.julialang.org/t/positioning-in-violin-plot/42678
**Category:** General Usage
**Tags:** plotting, statsplots
**Created:** [July 7, 2020, 2:51pm UTC](https://discourse.julialang.org/t/positioning-in-violin-plot/42678 "2020-07-07T14:51:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![smonsays](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@smonsays](https://discourse.julialang.org/u/smonsays)
#### Post date: [July 7, 2020, 2:51pm UTC](https://discourse.julialang.org/t/positioning-in-violin-plot/42678/1 "2020-07-07T14:51:49Z")

</div>

I would like to add ground truth values to a violin plot. So suppose I knew that for my category `"a"` the true value is `2.0` and I have a violin plot, I could use `scatter` like so:

```julia
violin(repeat(["a", "b", "c"], outer=100), randn(300), leg=false)
scatter!([(0.5, 2.0)])

```

Now I used an absolute value (0.5) to determine the x-position of the relevant violin plot which works in this toy example. Unfortunately, with my data, the violin plots use a different spacing, so I cannot just use `0.5, 1.5, 2.5 ...` as the x-positions.

How can I determine the correct x-position to add my ground truth value centered in the corresponding violin plot regardless of the shape of the data?

Thanks

Simon

---

<div class="post-metadata">

### Author: ![josephmarturano](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@josephmarturano](https://discourse.julialang.org/u/josephmarturano)
#### Post date: [July 7, 2020, 5:14pm UTC](https://discourse.julialang.org/t/positioning-in-violin-plot/42678/2 "2020-07-07T17:14:47Z")

</div>

One method might be to exploit the fact that `scatter!` can use a vector of strings for the x-positions. So something like this:

```julia
using StatsPlots
gr()
myviolin = violin(repeat(["a", "b", "c"], outer=100), randn(300), leg=false)
scatter!(["a", "b", "c"], [2,1,0], markersize=10) # note the x-argument
savefig(myviolin, "violin_with_markers.png")

```

![violin_with_markers](https://global.discourse-cdn.com/julialang/original/3X/2/3/2385e9f138b4568b2472aa36b6d7c740ef95ff23.png)

Does this work for your case?

---

<div class="post-metadata">

### Author: ![smonsays](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@smonsays](https://discourse.julialang.org/u/smonsays)
#### Post date: [July 8, 2020, 8:39am UTC](https://discourse.julialang.org/t/positioning-in-violin-plot/42678/3 "2020-07-08T08:39:16Z")

</div>

It does! What a simple and elegant solution, thanks a lot!
