[R] Label 2 groups in PCA different colours

Pedro Mardones mardones.p at gmail.com
Sun Sep 7 16:34:17 CEST 2008


here is a simple approach to, for instance, plot scores for PC1 and
PC2 using diff colors:

scores <- prcomp(yourdata)$x
plot(scores[1:100,1], scores[1:100,2], pch = 20, col = "blue")
points(scores[101:200,1], scores[101:200,2], pch = 20, col = "red")

PM

On Sat, Sep 6, 2008 at 11:44 PM, pgseye <prseye at gmail.com> wrote:
>
> Hi,
>
> I'm wanting to do a PCA on some data which is comprised of two different
> groups (to see how well the groups are discriminated). Is there a way to
> change the colour of the datapoints in a biplot so that I can easily see
> which group is which (eg objects 1-100, red, 101-200, black).
>
> Might be simple, but I'm new to R and can't seem to find how to do this.
>
> Thanks.
>
> Paul
> --
> View this message in context: http://www.nabble.com/Label-2-groups-in-PCA-different-colours-tp19354077p19354077.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list