Learn R Programming

inDAGO (version 1.0.0)

pcaPlot: pcaPlot

Description

Create a PCA scatter plot from log-expression data with sample labels.

Usage

pcaPlot(
  logcounts,
  Sample,
  Group,
  title,
  palette,
  maxOverlaps,
  sizeLabel,
  center,
  scale
)

Value

A "ggplot" object displaying the PCA scatter plot of PC1 vs PC2.

Arguments

logcounts

Numeric matrix of log-CPM values (genes × samples), e.g., from edgeR::cpm.

Sample

Character vector of sample names corresponding to the columns of "logcounts".

Group

Factor or character vector denoting group/condition for each sample.

title

Character. Title for the PCA plot.

palette

Character. Name of a discrete color palette from the "paletteer" package.

maxOverlaps

Integer. Maximum number of overlapping labels allowed by "ggrepel".

sizeLabel

Numeric. Font size for sample labels.

center

Logical. If TRUE, center variables before PCA.

scale

Logical. If TRUE, scale variables to unit variance before PCA.

Details

This function performs Principal Component Analysis (PCA) on a log-count matrix and visualizes the first two principal components using ggplot2 and ggrepel. Each point represents a sample, colored by group, with hover labels.

  1. Transposes the "logcounts" matrix so samples are rows.

  2. Runs PCA via "stats::prcomp()" with centering and scaling options.

  3. Calculates percent variance explained by PC1 and PC2.

  4. Builds a scatter plot with black‐bordered points and non‐overlapping labels.