[R] Legend help needed

Sean David Richards richars3 at lincoln.ac.nz
Mon Nov 15 02:08:10 CET 2004

R : Version 1.9.1


Am having trouble adding a legend to scatterplot. R code is shown below. 
I have tried various incantations to add a legend (using the legend() 
function) to the resulting plot but without any success. Looks like it 
should be simple but I must be missing something. Any pointers would be 
Have looked at help(legend) etc.


sfiles <- c("72_12_12_V.csv ",
## process each file in list
for (i in 1:length(sfiles)) {
data <- read.csv(paste("../data/",sfiles[i],sep=""))

## assign columns to some nice names
K <- data[,8]
AN <- data[,3] * (data[,2] - data[,4])

## plot K against AN

if ( i == 1) {
    plot(AN, K, ylim=c(1000,9000), xlim=c(0,1500), 
          xlab="Area above Notch (mm)",
          main="Size Effect Specimens")
    plot(AN,K, pch=(i),ylim=c(1000,9000), xlim=c(0,1500), 


Sean Richards

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