>I am using par(mfrow=c(3,2)) to plot 5 plots on a single page and was
>hoping to add the legend on top of the page using key() but it won't
>put the legend of top of the page. It keeps putting on bottom right.
key() doesn't have an "outer" argument like mtext, but it doesn't check
that x and y are within the plot region, so you should be able to get it
to work.
Idea 1 (quick and dirty):
Specify x and y, use trial and error. For example, this puts a key outside
the plot region of the active plot
par(mfrow=c(3,2))
plot(1:1)
plot(1:2)
plot(1:3)
plot(1:4)
plot(1:5)
key(text="normal")
key(x = 6.5, y = 8, text="y=8, x=6.5")
Idea 2 (more elegant):
The "Blue book" chapter 10 (The New S Language
Richard A. Becker, John M. Chambers, and Allan R. Wilks
Wadsworth & Brooks/Cole, Pacific Grove, CA (1988))
describes low-level control over graphics. You could do your plots,
then reset axes prior to calling key. Here's a quick example:
par(mfrow=c(3,2), oma = c(0,0,1,0))
plot(1:1)
plot(1:2)
plot(1:3)
plot(1:4)
plot(1:5)
par(mfrow=c(1,1), mar = rep(0,4))
key(corner=c(.5,1), text="at top")
If you want to place the key outside the plot region using the
"corner" argument, create a copy of key(), and change the call to
approx() near the top to allow linear extrapolation:
lambda <- approx(0:1, c(1, 99)/100, corner, rule=3)$y
Tim Hesterberg
========================================================
| Tim Hesterberg Research Scientist |
| timh@insightful.com Insightful Corp. |
| (206)802-2319 1700 Westlake Ave. N, Suite 500 |
| (206)283-8691 (fax) Seattle, WA 98109-3044, U.S.A. |
| www.insightful.com/Hesterberg |
========================================================
Download the S+Resample library from www.insightful.com/downloads/libraries
|