Hi list,

 

I've thus far not found a solution to my problem and hope someone can help.
I have a data matrix and wish to plot a stacked bar plot using barplot().
This is simple enough, but I have a problem with the legend labels being in
the reverse order from what I want.  The default appears to have labels
ascending bottom-to-top reflecting bottom-to-top sub-bars, but I would like
the labels to be the reverse, i.e. ascend top-to-bottom.  Please see my
example code below for an illustration of the problem.

 

For a reason unknown to me, if I plot a juxtaposed barplot using
beside=TRUE, the legend labels are actually in the order I want
(top-to-bottom labels).  Is there any way to make the legend appear the way
I want for a stacked barplot?  If one exists, I can't find an appropriate
argument to pass to args.legend.

Many thanks,

Tom

 

### START ###

A <- c(50,30,10,10)

B <- c(20,10,30,10)

mat <- cbind(A,B)

rownames(mat) <- c(1,2,3,4)

barplot(mat,legend.text=rownames(mat))    #legend labels are in wrong order
here

barplot(mat,legend.text=rownames(mat),beside=TRUE)    #correct order

### END ###


	[[alternative HTML version deleted]]

