# Grouped boxplot - https://github.com/JuliaPlots/StatsPlots.jl/pull/192

**URL:** https://discourse.julialang.org/t/grouped-boxplot-https-github-com-juliaplots-statsplots-jl-pull-192/44655
**Category:** Visualization
**Tags:** plotting, plots, statsplots
**Created:** [August 10, 2020, 1:33am UTC](https://discourse.julialang.org/t/grouped-boxplot-https-github-com-juliaplots-statsplots-jl-pull-192/44655 "2020-08-10T01:33:28Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Ibrahim-a-Ibrahim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ibrahim-a-ibrahim/32/17311_2.png) [@Ibrahim-a-Ibrahim](https://discourse.julialang.org/u/Ibrahim-a-Ibrahim)
#### Post date: [August 10, 2020, 1:33am UTC](https://discourse.julialang.org/t/grouped-boxplot-https-github-com-juliaplots-statsplots-jl-pull-192/44655/1 "2020-08-10T01:33:29Z")

</div>

I have a 3D array (24×3×3 Array{Float64,3}) as follows:  
x=rand(24,2,3)

How can I plot a grouped boxplot for x as shown in the following figure?  
 ![46959378-e3652400-d069-11e8-8157-8c0bd1f0c255](https://global.discourse-cdn.com/julialang/original/3X/b/7/b7c87d5ca4a582f207c2255204e611dd6809157f.png)

---

<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: [August 10, 2020, 12:14pm UTC](https://discourse.julialang.org/t/grouped-boxplot-https-github-com-juliaplots-statsplots-jl-pull-192/44655/2 "2020-08-10T12:14:54Z")

</div>

There’s a `groupedboxplot` recipe with the same syntax as grouped histograms [https://github.com/JuliaPlots/StatsPlots.jl#grouped-histograms](https://github.com/JuliaPlots/StatsPlots.jl#grouped-histograms)

---

<div class="post-metadata">

### Author: ![Ibrahim-a-Ibrahim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ibrahim-a-ibrahim/32/17311_2.png) [@Ibrahim-a-Ibrahim](https://discourse.julialang.org/u/Ibrahim-a-Ibrahim)
#### Post date: [August 14, 2020, 4:36pm UTC](https://discourse.julialang.org/t/grouped-boxplot-https-github-com-juliaplots-statsplots-jl-pull-192/44655/4 "2020-08-14T16:36:41Z")

</div>

Hi mkborregaard,

Thank you for your reply.

The groupedboxplot was not be able to represent the 3D array.  
According to the above figure, the sizes of x, y and z should be 2, 24 and 3, respectively. Therefore, let’s consider the random 3D array structure as rand(2,24,3). Here, using the groupedboxplot(rand(2,24,3)) just plotting x and y but neglecting z. (sorry I could not upload the figure as I am a new user. Can you please try it and see the results of groupedboxplot(rand(2,24,3))?)

Thank you again for your cooperation, and I look forward to hearing from you on this matter.

---

<div class="post-metadata">

### Author: ![Ibrahim-a-Ibrahim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ibrahim-a-ibrahim/32/17311_2.png) [@Ibrahim-a-Ibrahim](https://discourse.julialang.org/u/Ibrahim-a-Ibrahim)
#### Post date: [August 17, 2020, 1:07am UTC](https://discourse.julialang.org/t/grouped-boxplot-https-github-com-juliaplots-statsplots-jl-pull-192/44655/5 "2020-08-17T01:07:28Z")

</div>

I tried the following code and it sounds that it does not result any grouping.

```julia
using Plots
using StatsPlots

x = rand(2,24,3)
x1 = x[:,:,1]

groupedboxplot(x, bar_position = :dodge, bar_width=0.7)
groupedboxplot(x1, bar_position = :dodge, bar_width=0.7)

```

Any suggestion to end up with a grouped boxplot?

---

<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: [August 17, 2020, 11:55am UTC](https://discourse.julialang.org/t/grouped-boxplot-https-github-com-juliaplots-statsplots-jl-pull-192/44655/6 "2020-08-17T11:55:56Z")

</div>

You can’t use 3-d arrays - the easiest is to put the dataset in long format (x, y, group)

---

<div class="post-metadata">

### Author: ![Ibrahim-a-Ibrahim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ibrahim-a-ibrahim/32/17311_2.png) [@Ibrahim-a-Ibrahim](https://discourse.julialang.org/u/Ibrahim-a-Ibrahim)
#### Post date: [August 19, 2020, 9:01am UTC](https://discourse.julialang.org/t/grouped-boxplot-https-github-com-juliaplots-statsplots-jl-pull-192/44655/7 "2020-08-19T09:01:57Z")

</div>

I still confused. Could you please help to provide a piece of code for that?

---

<div class="post-metadata">

### Author: ![pszufe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pszufe/32/23452_2.png) [@pszufe](https://discourse.julialang.org/u/pszufe)
#### Post date: [June 1, 2023, 12:32am UTC](https://discourse.julialang.org/t/grouped-boxplot-https-github-com-juliaplots-statsplots-jl-pull-192/44655/8 "2023-06-01T00:32:53Z")

</div>

Perhaps kind of late but I came in this post when looking for `groupedboxplot`. Since other people can end here too, the answer is:

```julia
groupedboxplot(rand(["a","b"], 30), rand(30), group=rand(["C","D"], 30), legend=:bottom, bar_position = :dodge, bar_width=0.7)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/2/a206ee9450ab57d5326f4f725162e29ee07716c7.png)

---

<div class="post-metadata">

### Author: ![isaac.rubberducky](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/isaac.rubberducky/32/36791_2.png) [@isaac.rubberducky](https://discourse.julialang.org/u/isaac.rubberducky)
#### Post date: [November 10, 2023, 6:37pm UTC](https://discourse.julialang.org/t/grouped-boxplot-https-github-com-juliaplots-statsplots-jl-pull-192/44655/9 "2023-11-10T18:37:25Z")

</div>

> [@pszufe](#):
>
> `groupedboxplot(rand(["a","b"], 30), rand(30), group=rand(["C","D"], 30), le`

still useful!
