[R] using [i] to plot & label all vector elements

Robert Schick Robert.Schick at noaa.gov
Wed Jul 2 17:27:41 CEST 2003


I'm using 1.6.2 on a win 2k box. (I know I'm due for an upgrade.)

I've used brute force to label a series of vectors, and I'm wondering if
there's a better way to do this. I wanted to create a biplot of the 2nd
& 3rd PCs, and did this:

test <- edit(loadings(cv.prc.spr))
test.1 <- test[,1]
test.2 <- test[,2]
test.3 <- test[,3]
x0 <- 0
y0 <- 0
i <- order(test.1)
x <- test.1[i]
y <- test.2[i]
z <- test.3[i]

# and added the arrows to the pc plot with the following brute force
labeling.

arrows(x0, y0, x[i],y[i], length=0.1, lty=3)
text(x[i],y[i],labels=c("srnv", "ann.precip", "area.gt500", "modc" ,
"cscd","nwca", "range.ann.T", "mean.ann.T", "min.ann.T", "sedi", "gran",
"aluv", "cwca1", "elev", "volc", "gcv", "max.ann.T", "peak.flow.mnth"),
cex=.75)

When I tried using labels=rownames(x[i]) I get NULL. Three questions: 
1. Why is that statement NULL?
2. Is there a way to plot the labels without having to hard code them as
above. 
3. Even if I hard code them, there's something that seems to change in
the order of that that is eluding me. I suspect it's a combination of
[i] and order, but I don't understand it. Advice?

FWIW, test.1 looks like:
> test.1
     max.ann.T     mean.ann.T      min.ann.T           aluv          
cscd 
    -2.2162273     -2.1489203     -1.9744394     -1.2975221    
-1.1924917 
<snip>

-- 
Rob Schick
Ecologist
NOAA Fisheries
Santa Cruz Lab
110 Shaffer Road
Santa Cruz, CA 95060
Phone: 831.420.3960




More information about the R-help mailing list