🏥 🏭 Working on the COVID-19 response in Canada? Plotly & the Canadian government can help you and your organization. Learn more and get in touch.

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

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.

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.

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!

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

1 Like

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…