I would like to sort each histogram from a stacked barplot so that each column has the higher value at the bottom.
Here is an example of what i obtain that you can reproduce
library(plotly)
m <- matrix(0, ncol = 3, nrow = 20)
m <- data.frame(m)
colnames(m)= c("variable","sample","value")
m$variable <- rep(c("A","B","C","D","E"),4)
m$sample <- rep(paste("Sample",seq(1,4),sep="_"),each=5)
m$value = c(20,1,50,17,34,23,45,1,4,8,10,24,45,32,17,49,43,25,14,5)
plot_ly(m,
x = ~sample,
y = ~value,
color = ~variable,
type = "bar")%>%
layout(barmode = 'stack')
How can i sort each column so that most abundant values are sorted (the higher at the bottom at the bottom ???)