Learn R Programming

Momocs (version 0.1-01)

pca: Calculates and plots Principal Component Analysis.

Description

Calculates and plots Principal Component Analysis usng prcomp(). Methods for plotting a single PCA, a triple PCA and deformation grids are detailed below.

Usage

pca(Nef, fac = NA,PCa = 1, PCb = 2,
	col = "black", pch = 1, lty=1, shp.nb=NA, shp.size,
	shp.col="#00000022", shp.border="black", title = "Principal Component Analysis",
	legend = TRUE, lab = FALSE, lab.txt = rownames(Nef@coeff), lab.cex = 1, lab.box = TRUE,
	ell = TRUE, r = 1, lwd = 1, zoom.x = 0.25, zoom.y = 0.3)

pca3(Nef,  fac = NA,
	col = 1:nlevels(fac), pch = 1:nlevels(fac), lty = rep(1,nlevels(fac)),
	lab = FALSE, lab.txt = rownames(Nef@coeff), lab.cex = 1, lab.box = TRUE,
	ell = 1, r = 1, lwd = 1, zoom = 1.4, legend = FALSE)

pca.tps(Nef, fac = NA, PCa = 1, PCb = 2,
		col = "black", pch = 1, ell = TRUE, zoom = 1.4, ncells = 20,
		title = "Deformations alongs PC axes")

Arguments

Nef
the Nef object
fac
the grouping factor
PCa
integer corresponding to the a^th PCA axis to plot
PCb
integer corresponding to the a^th PCA axis to plot
col
integer or character indicating the col for each group to plot
pch
integer or character indicating the pch for each groups to plot
lty
integer indicating the lty for each confidence ellipse to plot
shp.nb
integer indicating how many, if any, shapes to plot
shp.size
numeric indicating the size of these shapes
shp.col
integer or a character indicating the color of these shapes
shp.border
integer or a character indicating the border color of these shapes
title
character to add a better title to the plot
lab
logical indicating whether to plot labels for every point
lab.txt
character vector containing labels names
lab.cex
numeric indicating the cex size of these labels
lab.box
logical indicating whether to draw a border for these labs
ell
logical indicating whether to draw confidence ellipses for every group
r
numeric indicating the number of standard deviations for confidence ellipses computation
lwd
numeric indicating the lwd for the confidence ellipses
zoom
numeric used to adjust the range of the plot
zoom.x
numeric used to adjust the x-range of the plot
zoom.y
numeric used to adjust the y-range of the plot
legend
logical indicating whether to add a legend on the plot
ncells
integer indicating the number of cells for deformation grids

Examples

Run this code
data(bottles.nef)
fac <- factor(rep(c("beer", "whisky"), each=20))

### pca
pca(bottles.nef)
pca(bottles.nef, fac=fac)
pca(bottles.nef, fac=fac, pch=c(4,5))
pca(bottles.nef, fac=fac, pch=c(4,5), ell=FALSE)
pca(bottles.nef, fac=fac,pch=c(4,5), lty=c(2,3))
pca(bottles.nef, pch=c(4,5), fac=fac, lty=c(2,3), col=c("dodgerblue","firebrick"))
pca(bottles.nef, fac=fac, lab=T)
pca(bottles.nef, fac=fac, lab=T, lab.cex=0.8)
pca(bottles.nef, fac=fac, lab=T, lab.box=FALSE)
pca(bottles.nef, fac=fac, lab=T, lab.txt=c(letters[1:20],LETTERS[1:20]))
pca(bottles.nef, fac=fac, r=0.5)
pca(bottles.nef, fac=fac, r=0.5, zoom.x=0.1, zoom.y=0.1)
pca(bottles.nef, PCa=2, PCb=3)
pca(bottles.nef, shp.nb=5)
pca(bottles.nef, shp.nb=5, shp.col="#FF660033", shp.border="#FF6600")

### pca3
pca3(bottles.nef)
pca3(bottles.nef, fac=fac)
pca3(bottles.nef, fac=fac, pch=c(4,5))
pca3(bottles.nef, fac=fac, pch=c(4,5), lty=c(2,3))
pca3(bottles.nef, fac=fac, pch=c(4,5), lty=c(2,3), col=c("dodgerblue","firebrick"))
pca3(bottles.nef, fac=fac, pch=c(4,5), lty=c(2,3), col=c("dodgerblue","firebrick"), legend=T)

### pca.tps
pca.tps(bottles.nef)
pca.tps(bottles.nef, fac=fac)

Run the code above in your browser using DataLab