plot_pca: PCA Plot

View source: R/plot_pca.R

plot_pcaR Documentation

PCA Plot

Description

This function plots a low-dimensional projection of an omic data matrix using principal component analysis.

Usage

plot_pca(
  dat,
  group = NULL,
  covar = NULL,
  top = NULL,
  pcs = c(1L, 2L),
  label = FALSE,
  pal_group = "npg",
  pal_covar = "Blues",
  size = NULL,
  alpha = NULL,
  title = "PCA",
  legend = "right",
  hover = FALSE,
  D3 = FALSE
)

Arguments

dat

Omic data matrix or matrix-like object with rows corresponding to probes and columns to samples. It is strongly recommended that data be filtered and normalized prior to plotting. Raw counts stored in DGEList or DESeqDataSet objects are automatically extracted and transformed to the log2-CPM scale, with a warning.

group

Optional character or factor vector of length equal to sample size, or up to two such vectors organized into a list or data frame. Supply legend title(s) by passing a named list or data frame.

covar

Optional continuous covariate. If non-NULL, then plot can render at most one group variable. Supply legend title by passing a named list or data frame.

top

Optional number (if > 1) or proportion (if < 1) of most variable probes to be used for PCA.

pcs

Vector specifying which principal components to plot. Must be of length two unless D3 = TRUE.

label

Label data points by sample name? Defaults to FALSE unless group and covar are both NULL. If TRUE, then plot can render at most one phenotypic feature.

pal_group

String specifying the color palette to use if group is non-NULL, or a vector of such strings with length equal to the number of vectors passed to group. Options include "ggplot", all qualitative color schemes available in RColorBrewer, and the complete collection of ggsci palettes. Alternatively, a character vector of colors with length equal to the cumulative number of levels in group.

pal_covar

String specifying the color palette to use if covar is non-NULL, or a vector of such strings with length equal to the number of vectors passed to covar. Options include the complete collection of viridis palettes, as well as all sequential color schemes available in RColorBrewer. Alternatively, a character vector of colors representing a smooth gradient, or a list of such vectors with length equal to the number of continuous variables to visualize.

size

Point size.

alpha

Point transparency.

title

Optional plot title.

legend

Legend position. Must be one of "bottom", "left", "top", "right", "bottomright", "bottomleft", "topleft", or "topright".

hover

Show sample name by hovering mouse over data point? If TRUE, the plot is rendered in HTML and will either open in your browser's graphic display or appear in the RStudio viewer.

D3

Render plot in three dimensions?

Details

This function plots the samples of an omic data matrix in a two- or three-dimensional principal component subspace. Axis labels include the percentage of variance explained by each component. PCA is an easy and popular projection method that can aid in identifying clusters, detecting outliers, and visualizing the latent structure of a dataset.

By default, plot_pca performs singular value decomposition on the complete dat matrix. Limit the PCA to only the most variable probes by using the top argument.

References

Hotelling, H. (1933). Analysis of a complex of variables into principal components. Journal of Educational Psychology, 24(6): 414:441.

Pearson, K. (1901). On lines and planes of closest fit to systems of points in space. Philosophical Magazine, 2(11): 559–572.

See Also

plotPCA, plot_mds, plot_tsne

Examples

mat <- matrix(rnorm(1000 * 5), nrow = 1000, ncol = 5)
plot_pca(mat)

library(DESeq2)
dds <- makeExampleDESeqDataSet()
dds <- rlog(dds)
plot_pca(dds, group = colData(dds)$condition)


dswatson/bioplotr documentation built on March 3, 2023, 9:43 p.m.