[R] Legend help needed

Sean David Richards richars3 at lincoln.ac.nz
Tue Nov 16 00:31:26 CET 2004


On 15 Nov 2004 at 12:11, Adaikalavan Ramasamy wrote:

> > Have you considered points() or lines() here ? You could simplify 
to
> > 
> > plot(0,1000, type="n", xlim=c(0,1500), ylim=c(1000,9000),
> >      xlab="Area above Notch (mm)", main="Size Effect Speciments")
> > 
> > n <- length(sfiles)
> > 
> > for (i in 1:n) {
> >   data <- read.csv(paste("../data/",sfiles[i],sep="")) 
> >   K    <- data[,8]
> >   AN   <- data[,3] * (data[,2] - data[,4])
> > 
> >   points( AN, K, pch=i, col=i )
> > }
> > 
> > legend( 1500, 9000, legend=paste("Data from", sfiles), pch=1:n, 
col=i:n)

Thanks this got me going on the right track. The code is a lot more 
concise as well :) 
Using locator() instead of x,y coord was suggested by Tom and that 
showed me where my problem was. The legend was being created just not 
where it would be visible.
I found this bit of code in the R-help archives and it makes thing a 
lot more straightforward when positioning a legend

## set the range of the usr coordinates to x = (0,1), y = (0,1) 
opar <- par(no.readonly=TRUE) 
par(usr=c(0,1,0,1)) 

## add the legend
legend(0.75,0.9,sub(".csv","",nfiles), pch=1:length(nfiles), cex=0.7)

Cheers

-- 
Sean Richards

C-fACS
P.O. Box 84, Lincoln University,
Canterbury, New Zealand
Phone:    (64)(3) 325-2811 ext 8636
Email:      richars3 at lincoln.ac.nz




More information about the R-help mailing list