[R] legend question

Sebastian P. Luque spluque at gmail.com
Wed Feb 28 18:21:38 CET 2007


On Wed, 28 Feb 2007 16:52:05 +0000 (GMT),
Jenny Barnes <jmb at mssl.ucl.ac.uk> wrote:

> Hi folks, Do you mind if I ask a related question that I have been
> having trouble with - how do you put the legend outside of the plot area
> (to the bottom of the area - below the x-axis title)? Could anybody show
> me using the example given below:

> x <- seq(-pi, pi, len = 65) plot(x, sin(x), type="l", col = 2) legend(x
> = -3, y = .9, "legend text", pch = 1, xjust = 0.5)

> Thank you, I've not been able to do this simple bit of programming and
> it is very frustrating not to be able to add a simple key.

Have a look at ?par and argument 'inset' in ?legend itself.  Here's one
way:


x <- seq(-pi, pi, len=65)
par(mar=c(par("mar")[1] + 2, par("mar")[-1]))
plot(x, sin(x), type="l", col=2)
par(xpd=TRUE)
legend("bottom", "legend text", pch=1, inset=-0.3)


-- 
Seb



More information about the R-help mailing list