# StatPlots groupedbar order x axis

**URL:** <https://discourse.julialang.org/t/statplots-groupedbar-order-x-axis/13912>\
**Category:** Visualization\
**Tags:** statsplots\
**Created:** [August 23, 2018, 12:46am UTC](https://discourse.julialang.org/t/statplots-groupedbar-order-x-axis/13912 "2018-08-23T00:46:23Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![JonasIsensee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonasisensee/32/4704_2.png) [@JonasIsensee](https://discourse.julialang.org/u/JonasIsensee)\
**Post date:** [June 12, 2020, 9:03am UTC](https://discourse.julialang.org/t/statplots-groupedbar-order-x-axis/13912/18 "2020-06-12T09:03:25Z")

</div>

Hi,

so I just figured out how to do it after a lot of digging.

The issue is that in  
`RecipesPipeline.jl` there is  
`group_labels = sort(collect(unique(v)))`

> <https://github.com/JuliaPlots/RecipesPipeline.jl/blob/304db22c33b64a902dd91606a8886ec371f62809/src/group.jl#L11>

Now in theory there are `CategoricalArrays` for this purpose,  
however `unique(ctg::CategoricalArray)` returns an ordinary `Vector{String}` instead of a new `CategoricalArray`.

Defining this solves the problem in this case

```julia
function Base.unique(ctg::CategoricalArray)
    l = levels(ctg)
    newctg = CategoricalArray(l)
    levels!(newctg, l)
end

```

```julia
ctg = CategoricalArray(["a", "b", "c", "a", "b", "c"])
levels!(ctg, ["c", "b", "a"])
groupedbar(1:6, group=ctg)

```

![test](https://global.discourse-cdn.com/julialang/original/3X/2/9/29d383b3527553c22200dd2d450af5c0e0017cea.png)

---

_[View the full topic](https://discourse.julialang.org/t/statplots-groupedbar-order-x-axis/13912)._
