[R] Re: color coding a legend - solved?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Jun 11 08:58:27 CEST 2003
On Tue, 10 Jun 2003, Robert Schick wrote:
> 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()
A common one. codes() is deprecated in the development version of R,
since it is much mis-used: indeed I could find no correct use in the R
sources nor any of the packages I examined.
> 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?
read the help page for biplot:
col: A vector of length 2 giving the colours for the first and
second set of points respectively (and the corresponding
axes). If a single colour is specified it will be used for
both sets.
A biplot both draws axes and plots points: there is no provision to
suppress the plotting. I'd start the other end, plotting the points as
in MASS, then add the variable axes.
--
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
More information about the R-help
mailing list