# Groupedbar, groupedhist, StatPlots, StatsPlots?

**URL:** <https://discourse.julialang.org/t/groupedbar-groupedhist-statplots-statsplots/89071>\
**Category:** New to Julia\
**Tags:** statsplots\
**Created:** [October 21, 2022, 3:45pm UTC](https://discourse.julialang.org/t/groupedbar-groupedhist-statplots-statsplots/89071 "2022-10-21T15:45:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Post date:** [October 21, 2022, 3:45pm UTC](https://discourse.julialang.org/t/groupedbar-groupedhist-statplots-statsplots/89071/1 "2022-10-21T15:45:28Z")

</div>

So, what function in what package is best for a bar chart with multiple datasets?

So far I’ve been looking at the `StatPlots` and `StatsPlots` packages and `groupedbar` and `groupedhist`. I’m not able to install the former package because of “Unsatisfiable requirements” but its `groupedbar` looks promising. The latter package looks fine but I haven’t found a tutorial or documentation that I can understand. The main documentation [GitHub - JuliaPlots/StatsPlots.jl: Statistical plotting recipes for Plots.jl](https://github.com/JuliaPlots/StatsPlots.jl) shows examples like

```julia
using RDatasets
iris = dataset("datasets", "iris")
@df iris groupedhist(:SepalLength, group = :Species, bar_position = :dodge)

```

which is totally foreign to me. I’m familiar with the standard `Plots` interface, with which you car plot regular arrays using a straightforward syntax like

```julia
p = plot()
plot!(p, xvec, yvec)
display(p)

```

I’m also able to use the `bar` function in the `Plots` package, but this one doesn’t seem to have a capability of plotting multiple datasets in a single bar chart.

I’m using julia Version 1.8.2 (2022-09-29) through the juliaup framework.

---

<div class="post-metadata">

**Author:** ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Post date:** [October 22, 2022, 10:46am UTC](https://discourse.julialang.org/t/groupedbar-groupedhist-statplots-statsplots/89071/2 "2022-10-22T10:46:25Z")

</div>

After my initial post above, I have gathered more information:

- It seems to me that Sta **t** Plots is obsolete. Its last update was 5 years ago. That’s the reason why it cannot be installed any longer.
- Sta **ts** Plots includes `groupedbar` although I haven’t found a documentation for it under Sta **ts** Plots.

Perhaps should I use `groupedbar` in Sta **ts** Plots and refer to the documentation under Sta **t** Plots?

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 22, 2022, 10:53am UTC](https://discourse.julialang.org/t/groupedbar-groupedhist-statplots-statsplots/89071/3 "2022-10-22T10:53:52Z")

</div>

It seem’s your question is lacking attention. I am currently not able to try some solution. Perhaps, in the meantime, you could provide some example plot (perhaps with some example data), so we can see which plot you exactly looking for.  
In general, a grouped bar plot is standard in all the main packages. So it should be no problem to give you some advise. I will be back in a few hours, but I am sure someone else will be faster.

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [October 22, 2022, 11:09am UTC](https://discourse.julialang.org/t/groupedbar-groupedhist-statplots-statsplots/89071/4 "2022-10-22T11:09:24Z")

</div>

> [@ryofurue](#):
>
> `@df iris groupedhist(:SepalLength, `

This is just a macro that lets you access the columns of a data frame as vectors using a symbol equal to the column name. So it’s doing what you expect. The `@df` macro is convenient but not required

---

<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:** [October 22, 2022, 12:29pm UTC](https://discourse.julialang.org/t/groupedbar-groupedhist-statplots-statsplots/89071/5 "2022-10-22T12:29:47Z")

</div>

Just to clarify, StatPlots and StatsPlots are the same package, its just that the package was named Statplots initially and then the name changed to StatsPlots to be consistent with other package in the Stats ecosystem.

So yes you should use StatsPlots and disregard anything related to StatPlots.

---

<div class="post-metadata">

**Author:** ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Post date:** [October 22, 2022, 7:16pm UTC](https://discourse.julialang.org/t/groupedbar-groupedhist-statplots-statsplots/89071/6 "2022-10-22T19:16:55Z")

</div>

An alternative would be Algebra of graphics

[https://aog.makie.org/stable/generated/analyses/](https://aog.makie.org/stable/generated/analyses/)

---

<div class="post-metadata">

**Author:** ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Post date:** [October 24, 2022, 8:32am UTC](https://discourse.julialang.org/t/groupedbar-groupedhist-statplots-statsplots/89071/7 "2022-10-24T08:32:04Z")

</div>

Thank you all for your inputs. Thanks to your advice, I’ve now been successful in producing the kind of bar charts that I need.

What I wanted to produce was similar to the `groupedbar(rand(10,3), bar_position = :dodge, bar_width=0.7)` example in the documentation of `StatsPlots` ( [GitHub - JuliaPlots/StatsPlots.jl: Statistical plotting recipes for Plots.jl](https://github.com/JuliaPlots/StatsPlots.jl) ). Initially, I didn’t notice this example.

Anyway, I pursed this avenue. Then, I had to deal with this bug: [How to unsort groupedbar categories · Issue #437 · JuliaPlots/StatsPlots.jl · GitHub](https://github.com/JuliaPlots/StatsPlots.jl/issues/437)  
of not being able to specify the ordering of the bars.

In any case, the workaround posted there solved the problem.

My final question is, why do we have to repeat the group names?

```julia
using StatsPlots
nams = ["G8", "G9", "G10", "G11", "G12"]
ctgs = ["W category", "A category"]
plot_ctgs = repeat(ctgs, inner = size(nams,1) ) # expand
plot_nams = repeat(nams, outer = size(ctgs,1) ) # expand
arr = rand(Float64, size(nams,1), size(ctgs,1))
#display(groupedbar(nams, arr)) # (1) fine
#display(groupedbar(nams, arr; group = plot_ctgs)) # (2) error
display(groupedbar(plot_nams, arr; group = plot_ctgs)) # (3) fine

```

(By the way, example (3) shows the ordering problem I mention above. The bars are ordered in the alphabetical order of the names and category names!)

---

<div class="post-metadata">

**Author:** ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Post date:** [October 24, 2022, 8:35am UTC](https://discourse.julialang.org/t/groupedbar-groupedhist-statplots-statsplots/89071/8 "2022-10-24T08:35:15Z")

</div>

> Algebra of graphics

That idea looks brilliant! I’ll explore it in the future. Thanks.
