Learn R Programming

inDAGO (version 1.0.0)

pcaPlottly: pcaPlottly

Description

Create an interactive PCA scatter plot using Plotly from log-expression data.

Usage

pcaPlottly(logcounts, Sample, Group, title, palette, center, scale)

Value

A Plotly object ( "plotly::ggplotly ") representing the interactive PCA scatterplot.

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.

center

Logical. If TRUE, center variables (genes) 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 generates an interactive plot of the first two principal components via "plotly::ggplotly()".

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

  2. Runs PCA with "stats::prcomp() ", using centering and scaling as specified.

  3. Computes percent variance explained by PC1 and PC2.

  4. Builds a ggplot2 scatterplot and converts it to an interactive Plotly graph.