[R] how can I make a legend that applies for all the barplots in one same page?
Jim Lemon
jim at bitwrit.com.au
Sat Oct 20 11:33:19 CEST 2012
On 10/20/2012 06:22 AM, Yakamu Yakamu wrote:
> Dear all,
> I would like to make 6 barplots in one page but with a legend that applies to all the barplots and would like to put it in the central-bottom of the page.
>
> I know only how to make legend for individual barplot, but since all my barplots have the same type and would be better if i just use one legend for all of them, and i cannot seem to find a way to put the legend in the bottom and centered.
> Please advice...
> I set the margins (and font type) as follows :
>
> par(mfrow=c(3,2),pty="m") # Layout with 3x2 plots
> par(oma=c(3,4,3,4)) # Outer margins
> par(mar=c(5,5,2,2)) # Inner margins
> par(xpd=F)
> par(family="serif", font=1) # Times New Roman font
>
Hi Yayu,
First, leave enough space below your plots, then:
# allow the legend to display outside the plots
par(xpd=TRUE)
# work out where you want the legend in the user coordinates
# of the _last_ plot displayed
legend(x,y,...)
par(xpd=FALSE)
Jim
More information about the R-help
mailing list