[R] Overall Legend

Spencer Graves spencer.graves at pdf.com
Mon Aug 22 06:08:58 CEST 2005


	  Since I haven't seen a reply to this post, I will attempt one.  Have 
you considered something like the following:

opar <- par(mfrow=c(2,2))

plot(1:2)
lines(2:1, col="blue")
legend("top", legend=c("black", "blue"),
        text.col=c("black", "blue"))
# with a legend on one of the four plots

plot(3:4)
plot(5:6, col="blue")

# Or using mtext to construct a legend in the outer margin
mtext("black", side=3,line=-2, at=.4, outer=TRUE,col="black")
mtext("blue", side=3,line=-2, at=.6, outer=TRUE,col="blue")

par(opar)

##############
RSiteSearch("one legend for multiple plots") identified the following
that discusses placing a single legend with trellis graphics:

http://finzi.psych.upenn.edu/R/Rhelp02a/archive/1834.html

	  Also, have you checked Venables and Ripley (2002) Modern Applied 
Statistics with S (Springer)?  I don't have a copy handy, but if my 
memory is correct, they have something relevant to this question.

	  Perhaps someone else will reply with better information than this.
	  spencer graves

Juned Siddique wrote:

> Hello. I am using R version 2.1.1 on Windows 2000.
> 
> I am using a par(mfrow=c(2,2)) statement to produce 4 plots on one screen. 
I want a single horizontal legend to appear at the top of the four plots.
My code is something like this:
> 
> par(mfrow=c(2,2))
> 
> plot(x,y1)
> lines(x,y2)
> lines(x,y3)
> 
> plot(x,z1)
> lines(x,z2)
> lines(x,z3)
> 
> plot(x,t1)
> lines(x,t2)
> lines(x,t3)
> 
> plot(x,w1)
> lines(x,w2)
> lines(x,w3)
> 
> Instead of the statement:
> legend(x="right", c("Bias Squared","Variance","Mean Squared Error"), 
lty=c(2,1,3), col=c("green","blue","red"), lwd="2",cex=0.5,inset = 0.05)
> 
> appearing within each plot, I would like it to appear at the top of 
the graph because it applies to all four plots. Any help would be
appreciated. Thank you.
> 
> -Juned
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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

-- 
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA

spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel:  408-938-4420
Fax: 408-280-7915




More information about the R-help mailing list