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.1max.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
On Wed, 2 Jul 2003, Robert Schick wrote:> 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:You seem to be using the 1st and 2nd. What's wrong with biplot()'s princomp method (which can do any pair)?> 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?x[i] is a single vector, not a matrix. It is matrices which have rownames. names() would have worked.> 2. Is there a way to plot the labels without having to hard code them as > above..Yes.> 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?We can't see that from the details you have given. Try working with the matrix directly: test2 <- test[sort.list(test[, 1], ] arrows(0, 0, test2[, 1], test2[, 2], length=0.1, lty=3) text(test2[, 1:2], labels=rownames(test2), cex=0.75- However, in this case there is no point in permuting the rows, so what exactly did you intend? -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Robert Schick wrote:> 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 ...I was unhappy with the standard biplot routine (the arrows didn't have tick marks) so I wrote my own, a lattice version. It may be of some help, but I should warn you that it is not wrapped up in a package, and there are undoubtedly bugs. http://www.statslab.cam.ac.uk/~djw1005/Stats/Interests/biplot.html If m is a matrix with named rows and columns, you would invoke it by res <- princompfull(m) xyaplot (y~x, data=res$observations, axes=y~x, data.axes=res$variables, subset.axes=c(FALSE,TRUE,TRUE,...), # whichever vectors to plot axes.spec=list(origin="o",min="min",max="max",ticks=TRUE), label="label", label.axes="label") (The last two lines are a silly incantation which I will eventually tidy up.) Damon.