Re: [R] plot and legend

From: Gavin Simpson <gavin.simpson_at_ucl.ac.uk>
Date: Fri 19 Aug 2005 - 20:52:51 EST

On Thu, 2005-08-18 at 18:19 +0200, svenknueppel@reilich.net wrote:
> Hello,
>
> I would like make a plot with a legend. How can I take the legend
> outside of the plot frame?
>

Does this do what you want?

## change the plotting parameters and store defaults
## mar sets 2 more lines in the margin than default at the top
## xpd = TRUE stops clipping to the plot region only
oldpar <- par(mar = c(5, 4, 6, 2) + 0.1, xpd = TRUE)

## do a plot
plot(1:10)

## now build a legend, the y co-ordinate pushes the legend outside the
## plotting region - x & y are on same scale as your axes
## xjust = 0.5 centres the legend on the x coordinate
legend(x = 5.5, y = 11.5, "legend text", pch = 1, xjust = 0.5)

##restore the defaults
par(oldpar)

It would be nice if legend allowed the use of "top" etc. to relate to the device if the user wanted. It would simplify this kind plot arrangement.

HTH G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson                     [T] +44 (0)20 7679 5522
ENSIS Research Fellow             [F] +44 (0)20 7679 7565
ENSIS Ltd. & ECRC                 [E] gavin.simpsonATNOSPAMucl.ac.uk
UCL Department of Geography       [W] http://www.ucl.ac.uk/~ucfagls/cv/
26 Bedford Way                    [W] http://www.ucl.ac.uk/~ucfagls/
London.  WC1H 0AP.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri Aug 19 21:07:00 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:33:36 EST