I'm inexperienced with ggplot, so apologize if I've missed something simple. I'm using ggplot2_0.9.3.
I'd like to generate a bar plot from an input data frame in which rows are sorted by descending value of a column. I'd like the bar plot to retain this record order. Big bars at the top, small at the bottom. Each bar has a label (a GO term), and a label is put beside its bar.
When I generate the plot, the bars are reordered so that the labels are in order. In the example below, the plot's bars will be reordered to put bar 3 is at the top and 1 at the bottom. I'd like the bars to be in the order they are in, in df.o.
> df <- data.frame( labs=c(2,1,3), vals=c(1.1,3.3,2.2) )
> df
labs vals
1 2 1.1
2 1 3.3
3 3 2.2
> df.o <- df[order(-df$vals),]
> df.o
labs vals
2 1 3.3
3 3 2.2
1 2 1.1
> pt <- ggplot( df.o, aes(x=labs, y=vals) )
> pt + geom_bar(stat="identity", fill="white", width=0.8, colour="darkgreen") + coord_flip()
# plotted as:
#3 2.2
#2 1.1
#1 3.3
Thanks for your help.
G
--
Gordon Robertson
Michael Smith Genome Sciences Centre