How do I set the order of categorical elements plotted in a bar chart?


#1

Hi!

Just started using plotly and love it!
However I’m struggling figuring out how to order the elements in the y-axis of a bar chart as I would like. I added a simple example here:

example plot: https://plot.ly/145/~kevinmfranklin/

Here I would like to order them by name1, name2, name3, … Basically you see the increasing contribution of different types of contributors. I want the color coding of the category to be mixed. Please help!! I’m working via the website.


#2

Unfortunately, this is no easy way to set the order of categorical entries at the moment.

See answer to How to sort bar's in a bar chart for a workaround.

I hope this helps.


#3

Dear @etienne,
I found I can order the categorical axis by setting the “categoryorder” and “categoryarray”, when I first plot it, however the “relayout” doesn’t seem to support this:

You can see the order changed if I specify that in the “layout” before plot, but the “relayout” doesn’t work. I wonder is there any way to reorder the plotted chart? Thank you!


#4

Here’s a working version: https://codepen.io/etpinard/pen/YrEeGG?editors=1010


#5

Dear @etienne,
Thanks for the quick reply, that works great! I wonder is there any way to make the reordering of the following case work?

https://codepen.io/anon/pen/EwbQRV?editors=0010

I have a scatter trace because I’d like the points to be selectable. Then essentially the y axis is not categorical any more, so the “categoryorder” trick seems not working…