# Groupedbar plotting not as expected

**URL:** <https://discourse.julialang.org/t/groupedbar-plotting-not-as-expected/95545>\
**Category:** Visualization\
**Created:** [March 4, 2023, 3:28pm UTC](https://discourse.julialang.org/t/groupedbar-plotting-not-as-expected/95545 "2023-03-04T15:28:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dasavy](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@dasavy](https://discourse.julialang.org/u/dasavy)\
**Post date:** [March 4, 2023, 3:28pm UTC](https://discourse.julialang.org/t/groupedbar-plotting-not-as-expected/95545/1 "2023-03-04T15:28:49Z")

</div>

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

I have no idea why N=8 is going to the far right and isn’t on the far left. Please let me know if anyone knows what’s happening here

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [March 4, 2023, 3:31pm UTC](https://discourse.julialang.org/t/groupedbar-plotting-not-as-expected/95545/2 "2023-03-04T15:31:38Z")

</div>

It’s sorting the labels alphabetically, where `"16"` comes before `"8"`. Maybe there is a way to have the grouping be numbers, with a separate way to pass the string labels? Not sure.

---

<div class="post-metadata">

**Author:** ![dasavy](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@dasavy](https://discourse.julialang.org/u/dasavy)\
**Post date:** [March 4, 2023, 5:22pm UTC](https://discourse.julialang.org/t/groupedbar-plotting-not-as-expected/95545/3 "2023-03-04T17:22:05Z")

</div>

Yeah I kinda figured that but it still bug me because I haven’t been able to figure out a way to get what I want

---

<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:** [March 4, 2023, 5:42pm UTC](https://discourse.julialang.org/t/groupedbar-plotting-not-as-expected/95545/4 "2023-03-04T17:42:14Z")

</div>

> [@StatPlots groupedbar order x axis](https://discourse.julialang.org/t/statplots-groupedbar-order-x-axis/13912/18):
>
> 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))) 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 function Base.unique(ctg::CategoricalArray) l = levels(ctg) newctg = CategoricalArray(l) levels!(newctg, l) end c…

---

<div class="post-metadata">

**Author:** ![dasavy](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@dasavy](https://discourse.julialang.org/u/dasavy)\
**Post date:** [March 8, 2023, 11:35am UTC](https://discourse.julialang.org/t/groupedbar-plotting-not-as-expected/95545/5 "2023-03-08T11:35:11Z")

</div>

This worked!! Thank you very much

 ![2](https://global.discourse-cdn.com/julialang/original/3X/2/4/2469ef933e8ee1cae1d5b2958d622d7cdd3ca07e.png)
