I did the following, and had it plot as needed: >legend(3.25, -2.5, leg.txt, pch=15, col=
levels(as.factor(codes(cv.wshed.grp))))
Problem was in my (lack of) understanding of codes()
But my second question is this: is there a way to color code the points
on the first two PCA axes by group id within a biplot. Fig 11.7 in MASS
4 is my inspiration, but I don't understand how to use the col variable
within biplot. The following works within a simple plot, but not a
biplot:
>text(cv.mds.spr$points, labels = as.character(cv.wshed.id.spr), col =
levels(as.factor(codes(cv.wshed.grp))), cex=.75)
Advice?
Robert Schick wrote:>
> I'm using R 1.6.2 on a Windows 2000 machine.
>
> I've plotted the results of an MDS run labeled by a numerical ID, and
> color coded by a group code:
>
> plot(cv.mds.spr$points, type="n", main="Non-Metric
Multidimensional
> Scaling of SprRun CV Watersheds")
> text(cv.mds.spr$points, labels = as.character(cv.wshed.id.spr), col >
codes(cv.wshed.grp), cex=.75)
>
> Question is, how do I get the legend to match the color codes?
>
> I have tried different permutations of the following:
> leg.txt <-
c("LSSJ.NS","LSSJ.SS","US.RD","US.SF")
# the groups in
> cv.wshed.grp
> legend(-6.5, -2.5, leg.txt, pch="1234", col>
as.character(codes(cv.wshed.grp)))
>
> But this only plots the codes in cv.wshed.grp as they are encountered,
> not the levels. Ideally I'd like the legend to have the Group ID label,
> and a filled box corresponding to the colors in the text call above.
>
> --
> Rob Schick
> Ecologist
> NOAA Fisheries
> Santa Cruz Lab
> 110 Shaffer Road
> Santa Cruz, CA 95060
> Phone: 831.420.3960
--
Rob Schick
Ecologist
NOAA Fisheries
Santa Cruz Lab
110 Shaffer Road
Santa Cruz, CA 95060
Phone: 831.420.3960