How do I change the order of bars for a barplot generated from a data frame?
I tried code from here: R - ordering in boxplot but it seems to only work for boxplots, e.g.
foo=data.frame(a=c(1,2,3),b=c("a","b","c"))
barplot(height=foo$a,names.arg=foo$b)
boxplot(foo$a~foo$b)
foo$c=factor(foo$b,c("c","b","a"))
barplot(height=foo$a,names.arg=foo$c)
boxplot(foo$a~foo$c)
This worked for me
foo$c=factor(foo$b, levels = c("c","b","a"))
foo <- foo[order(foo$c), ]
barplot(height=foo$a,names.arg=foo$c)