1

I'm trying to make a stacked barplot but the legends either overlap the bars, thus making it impossible to see them, or become incomplete when I use args.legend() to move them to the right:

barplot(data, legend=rownames(data), las=1) produces legends that overlap with the bars; while

barplot(data, legend=rownames(data),args.legend=list(x=3.8, bty="L"), las=1) moves the legends to the right, fixing the overlapping problem, but causing part of the legends to go outside the canvas, thus dissappearing.

I obtained datadata with tapply() and it looks like this:

enter image description here

*I'm using Rstudio in a Mac.

cgog
  • 53
  • 1
  • 6
  • Please provide a reproducible example. This will give people who want to help you something to work with and to test. You can read about it **[here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)**. In your case, provide the data with `dput` in stead of a picture. – KoenV Sep 15 '17 at 07:10

1 Answers1

0

I suggest you to move the plot margins:

par(mar=c(5, 20, 4, 2)) 

and then play a little with the legend:

legend=rownames(t(data)),args.legend=list(x=3.5, y=12))

I changed all the margins to ten (par(mar=c(10, 10, 10, 10))) to experiment. It is a little bit drastic. See what works better for you.