[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

Hi,

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 
welcome.
Have looked at help(legend) etc.

--8<----------------------------------------------------------------------
---

sfiles <- c("72_12_12_V.csv ",
            "150_25_15_V.csv",    
            "150_25_20_V.csv",    
            "150_25_25_V.csv",    
            "150_25_40_V.csv",    
            "150_25_60_V.csv",    
            "150_25_90_V.csv",    
            "240_40_40_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")
    par(new=TRUE)                        
    }
else{
    plot(AN,K, pch=(i),ylim=c(1000,9000), xlim=c(0,1500), 
          axes=FALSE,xlab="")
    par(new=TRUE)
    }
}

--8<----------------------------------------------------------------------
---

-- 
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