# Gardner-Altman Plots in Julia

**URL:** <https://discourse.julialang.org/t/gardner-altman-plots-in-julia/29286>\
**Category:** Visualization\
**Created:** [September 29, 2019, 7:18am UTC](https://discourse.julialang.org/t/gardner-altman-plots-in-julia/29286 "2019-09-29T07:18:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clement\_POIRET](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/clement_poiret/32/10534_2.png) [@Clement\_POIRET](https://discourse.julialang.org/u/Clement_POIRET)\
**Post date:** [September 29, 2019, 7:18am UTC](https://discourse.julialang.org/t/gardner-altman-plots-in-julia/29286/1 "2019-09-29T07:18:43Z")

</div>

Hi everyone,

I’m switching from Python to Julia, and I’m interested in Estimation Statistics to replace classical NHST approach. To do so, I’d like to make Gardner-Altman Plots in Julia but I have to say I’m a bit confused on how to produce it.

Here is a GA Plot:  
 ![GAP](https://global.discourse-cdn.com/julialang/original/3X/7/2/7274b8157cdda830cc248fe442c06d3f4d52662f.png)

So we have two swarmplots representing our 2 independant groups with the effect size and 95% confidence interval on the right plotted over a bootstrap distribution.

In python, we have the library “DABEST”, but I don’t know how to do this in Julia.

Can you help me please?  
Thanks,  
Clément.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 29, 2019, 7:48am UTC](https://discourse.julialang.org/t/gardner-altman-plots-in-julia/29286/2 "2019-09-29T07:48:01Z")

</div>

I don’t know of any plotting packages that could currently do this easily out of the box - you’d need to make a function constructing the plot yourself.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [September 29, 2019, 8:24am UTC](https://discourse.julialang.org/t/gardner-altman-plots-in-julia/29286/3 "2019-09-29T08:24:48Z")

</div>

Maybe check out the violin ploys in StatsPlots [here](https://github.com/JuliaPlots/StatsPlots.jl/blob/master/README.md#boxplot-dotplot-and-violin) for some inspiration - but I agree that you’ll have to do some calculations yourself to construct the bootstrap distribution

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [September 29, 2019, 9:21am UTC](https://discourse.julialang.org/t/gardner-altman-plots-in-julia/29286/4 "2019-09-29T09:21:11Z")

</div>

Another alternative is to simply call the python code using PyCall

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 29, 2019, 12:14pm UTC](https://discourse.julialang.org/t/gardner-altman-plots-in-julia/29286/5 "2019-09-29T12:14:39Z")

</div>

I would have suggested that as well. Normally you’d just write a recipe if yuo wanted to use (Stats)Plots - but the beeswarm plot PR has not yet been merged on StatsPlots. With beeswarm you could write a userplot recipe with two panels, put the y axis on the right of the second panel, and the legend outside and to the left of the first panel. Then just use group to create the colors. The density plot etc can be found int StatsPlots.

If someone can finish the beeswarm PR I’m happy to add this plot type to StatsPlots 😃

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [September 29, 2019, 1:35pm UTC](https://discourse.julialang.org/t/gardner-altman-plots-in-julia/29286/6 "2019-09-29T13:35:51Z")

</div>

Here’s a [Gadfly](http://gadflyjl.org/dev/) example, similar to this [plot](https://github.com/ACCLAB/DABEST-python#usage):

```julia
using DataFrames, Gadfly, RDatasets, Statistics
iris = dataset("datasets","iris")
irm = by(iris, :Species, :PetalWidth=>mean)
boot(x; n=200) = [mean(rand(x, length(x))) for i in 1:n]
Db = by(iris, :Species, μ=:PetalWidth=>boot)
Db.μdiff = Db.μ - repeat(Db[Db.Species.=="setosa", :μ], outer=3)
labeld = Dict("setosa"=>"", "versicolor"=>"versicolor\n minus\n setosa", 
  "virginica"=>"virginica \n minus\n setosa" )
p1 = plot(
  layer(iris, x=:Species, y=:PetalWidth, color=:Species, Geom.beeswarm),
  layer(irm, yintercept=:PetalWidth_mean, Geom.hline(color="grey", style=:dash)),
    Guide.xlabel(nothing), Theme(key_position=:none)
)
p2 = plot(Db, x=:Species, y=:μdiff, color=:Species,
        Geom.violin, Coord.cartesian(ymin=1, ymax=2),
    Scale.x_discrete(labels=i->labeld[i]),
    Guide.xlabel(nothing), Guide.ylabel("Mean difference"), 
    Theme(key_position=:none)
)
vstack(p1, p2)

```

 ![iris](https://global.discourse-cdn.com/julialang/original/3X/f/a/fa7b2cd681f5182013cbaf3ea50438218250c19f.png)
