Skip to content

plot and legend

3 messages · svenknueppel@reilich.net, Uwe Ligges, Gavin Simpson

#
Hello,

I would like make a plot with a legend. How can I take the legend
outside of the plot frame?

Greetings, Sven Knüppel (Berlin, Germany)
#
svenknueppel at reilich.net wrote:

            
Use par(xpd = .....)
See ?par for details.

Uwe Ligges
#
On Thu, 2005-08-18 at 18:19 +0200, svenknueppel at reilich.net wrote:
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