[R] how can I make a legend that applies for all the barplots in one same page?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Oct 20 11:40:08 CEST 2012
On 20/10/2012 10:33, Jim Lemon wrote:
> 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(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
> # work out where you want the legend in the user coordinates
> # of the _last_ plot displayed
It is clearer and safer to use
legend(x,y, ..., xpd = TRUE)
See the help page.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help