I am trying to create a stacked bar plot, but I cannot position the legend so that it does not overlap any of the bars. I have tried adjusting the margins, setting xl
xl
How about this:
library(RColorBrewer) barplot( y, xlim=c(0, ncol(y) + 3), col=brewer.pal(nrow(y), "Paired"), ylab="My Variables", legend.text=TRUE, args.legend=list( x=ncol(y) + 3, y=max(colSums(y)), bty = "n" ) )