Skip to content
Prev 389226 / 398502 Next

order stacked bar plot from total frequency

Hi Kai,
I don't know about ggplot, but it may be easier to do it before plotting:

set.seed(753)
testdat<-matrix(sample(1:10,9),nrow=3)
# first plot the raw matrix
barplot(testdat)
# then plot the matrix ordered by column sums
barplot(testdat[,order(colSums(testdat))])

Jim

On Fri, Sep 17, 2021 at 4:01 AM Kai Yang via R-help
<r-help at r-project.org> wrote: