Learn R Programming

mt (version 2.0-1.20)

pcaplot: Plot Function for PCA with Grouped Values

Description

Plot function for PCA with grouped values.

Usage

pcaplot(x, y, scale = TRUE, pcs = 1:2, ...)

pca.plot(x, y, scale=TRUE, abbrev = FALSE, ep.plot=FALSE,...)

pca.comp(x, scale=FALSE, pcs=1:2,...)

Value

pcaplot returns an object of class "trellis".

pca.comp returns a list with components:

scores

PCA scores

vars

Proportion of variance

varsn

A vector of string indicating the percentage of variance.

Arguments

x

A matrix or data frame to be plotted.

y

A factor or vector giving group information of columns of x.

scale

A logical value indicating whether the data set x should be scaled.

pcs

A vector of index of PCs to be plotted.

ep.plot

A logical value indicating whether the ellipse should be plotted.

abbrev

Whether the group labels are abbreviated on the plots. If abbrev > 0 this gives minlength in the call to abbreviate.

...

Further arguments to prcomp or lattice. See corresponding entry in xyplot for non-trivial details of lattice. For pcaplot, one argument is ep: an integer for plotting ellipse. 1 and 2 for plotting overall and group ellipse, respectively. Otherwise, none. For details, see panel.elli.1.

Author

Wanchang Lin

See Also

grpplot, panel.elli.1, pca_plot_wrap

Examples

Run this code
## examples of 'pcaplot'
data(iris)
pcaplot(iris[,1:4], iris[,5],pcs=c(2,1),ep=2)
## change confidence interval (see 'panel.elli.1')
pcaplot(iris[,1:4], iris[,5],pcs=c(1,2),ep=2, conf.level = 0.9)

pcaplot(iris[,1:4], iris[,5],pcs=c(2,1),ep=1,
        auto.key=list(space="top", columns=3))
pcaplot(iris[,1:4], iris[,5],pcs=c(1,3,4))
tmp <- pcaplot(iris[,1:4], iris[,5],pcs=1:3,ep=2)
tmp

## change symbol's color, type and size
pcaplot(iris[,1:4], iris[,5],pcs=c(2,1),main="IRIS DATA", cex=1.2,
  auto.key=list(space="right", col=c("black","blue","red"), cex=1.2),
  par.settings = list(superpose.symbol = list(col=c("black","blue","red"),
                                              pch=c(1:3))))

## compare pcaplot and pca.plot. 
pcaplot(iris[,1:4], iris[,5],pcs=c(1,2),ep=2)
pca.plot(iris[,1:4], iris[,5], ep.plot = TRUE)

## an example of 'pca.comp'
pca.comp(iris[,1:4], scale = TRUE, pcs=1:3)

Run the code above in your browser using DataLab