[R] how can I make a legend that applies for all the barplots in one same page?

Greg Snow 538280 at gmail.com
Fri Oct 19 21:50:52 CEST 2012


First of all, in the command par(xpd=F), what is the value of F?  If
it is the default value of FALSE then that says to not plot anything
outside of the plot region, so any attempts to put a legend in the
outer margin will not plot anything.  if F is TRUE (which is a recipe
for disaster) then you can put things into the figure region (inner
margins) but it will still not plot in the outer regions.  Only if F
is NA will it allow plotting in the outer margin.  That is why it is
best practice not to use F and T, but to spell out the logical names.
Best for this case is par(xpd=NA).  Now you can plot in the outer
margins.  Use the grconvertX and grconvertY functions to find the
location to put the legend, then use the legend function to plot it.

On Fri, Oct 19, 2012 at 1:22 PM, Yakamu Yakamu <iam_yakamu at yahoo.com> 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
>
> ANy great help is kindly appreciated,
> cheers,
> Yayu
>
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com




More information about the R-help mailing list