I have some data that is sorted but in plotly the horizontal bar is only sorting in reverse alphabetical order but I need it to sort by a VALUE which is a number; see image 'YOY' column. enter image description here
ecomm_yoy <- ecomm_data2019 %>%
inner_join(ecomm_data2018, by = "Brand") %>%
mutate(YOY = round(((Value.x - Value.y)/Value.y)*100, 2))
ecomm_yoy2 <- ecomm_yoy[order(-ecomm_yoy$YOY),]
plot_ly(x = ecomm_yoy2$YOY, y = ecomm_yoy2$Brand, type = 'bar', orientation = 'h')
enter image description here
Add (using a pipe) this layout to your chart:
layout(yaxis = list(categoryorder = "array", categoryarray = ecomm_yoy2$YOY))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With