plotPCA.prcomp: Visualise PCA results of expression data with the sample plot

View source: R/pcaPlots.R

plotPCA.prcompR Documentation

Visualise PCA results of expression data with the sample plot

Description

plotPCA is designed to visualize sample relationships revealed by PCA analysis of high-dimensional expression data. It is adapted from the biplot function in the stats package, with functionalities useful for sample visualization and labelling, and removing the visualization of features (usually genes) in the input matrix. The rationale is that in most cases there are too many features to provide an informative visualization.

Usage

## S3 method for class 'prcomp'
plotPCA(
  x,
  choices = c(1, 2),
  text = FALSE,
  points = list(pch = NULL, col = NULL, cex = NULL, bg = NULL, lwd = NULL, lty = NULL,
    order = NULL),
  arrows = FALSE,
  grid = FALSE,
  abline = FALSE,
  xlim = NULL,
  ylim = NULL,
  xlab = NULL,
  ylab = NULL,
  offset,
  main = NULL,
  reverse = c(FALSE, FALSE),
  ...
)

Arguments

x

prcomp object produced by the prcomp function

choices

An integer vector of length 2, indicating which PCs to visualize. By default the first (X-axis) and second (Y-axis) are visualized

text

A logical value or a list of options to label samples. See Details.

points

A logical value or a list of options to pinpoint samples. See details.

arrows

A logical or a list of options to draw arrows.

grid

Logical value, indicating whether grid lines should be added to the plot.

abline

A logical or a list of options to draw abline

xlim

xlim of the plot. Automatically determined if missing.

ylim

ylim of the plot. Automatically determined if missing.

xlab

xlab of the plot. If missing, the PC and the explained variability are shown.

ylab

ylab of the plot. If missing, the PC and the explained variability are shown.

offset

Offset should be either one or more rows's names in the loading matrix, or indices, or a logical vector. The average loading of the rows specified by offset is set to zero.

main

Title of the plot

reverse

ogical of length 2 or 1 (which will be repeated to 2), indicating whether the sign of values in the 1st/2nd axis should be reversed.

...

Other parameters passed to plot.window

Details

The values for text, points and arrows can be

  1. Logical. If FALSE, no text or point is added.

  2. List. A list containing options passed to text, points, and arrows respectively, such as col, cex, lwd, lty, code, length,angle, and pos (only for text). order decides in what order are the points drawn, which can be useful when there are points to be drawn 'above' other points.

  3. A vector of character strigns (only for text)

See examples below.

Value

The value of the rotated data, namely the centered (and scaled if requested) data multiplied by the rotation matrix.

Note

prcomp should be called with retx=TRUE, which is the default behaviour.

See Also

prcomp and pcaScores

Examples


testVal <- matrix(rnorm(10000), nrow=500)
colnames(testVal) <- paste("Sample", 1:ncol(testVal), sep="")
rownames(testVal) <- paste("Gene",1:nrow(testVal), sep="")

testPCA <- prcomp(t(testVal), center=TRUE, scale=TRUE)


plotPCA(testPCA)

plotPCA(testPCA, points=FALSE, text=TRUE, grid=TRUE)

pointsList <- list(col=1:3, bg=21,pch=22, cex=4:1, lwd=1:2, lty=2:4)
textList <- list(col=c("orange", "royalblue"), cex=1.2, srt=15, pos=1)

plotPCA(testPCA, choices=c(1,2), grid=TRUE, points=pointsList,
        text=TRUE)

## visualize dimension 1:3
rop <- par(mfrow=c(1,2), pty="s")
plotPCA(testPCA, choices=c(1,2), grid=TRUE, points=pointsList, text=textList)
plotPCA(testPCA, choices=c(2,3), grid=TRUE, points=pointsList, text=textList)


bedapub/ribiosPlot documentation built on Sept. 1, 2023, 6:50 p.m.