pcaplot: Plot Function for PCA with Grouped Values

Description Usage Arguments Value Note Author(s) See Also Examples

View source: R/mt_util.R

Description

Plot function for PCA with grouped values.

Usage

1
2
3
4
5
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,...)

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.

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.

Note

Number of columns of x must be larger than 1. pcaplot uses lattice to plot PCA while pca.plot uses the basic graphics to do so. pca.plot plots PC1 and PC2 only.

Author(s)

Wanchang Lin

See Also

grpplot, panel.elli.1, pca.plot.wrap

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## 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)

mt documentation built on Nov. 15, 2021, 9:06 a.m.

Related to pcaplot in mt...