ggpca: ggplot2-based PCA plot

View source: R/plot_utils.R

ggpcaR Documentation

ggplot2-based PCA plot

Description

Create an eigenvectors scatterplot from principal component analysis.

Usage

ggpca(
  data,
  group_var = NULL,
  pc_x = 1,
  pc_y = 2,
  ntop = nrow(data),
  center = T,
  scale = T,
  equal_axes = F,
  point_size = 3,
  alpha = 0.75,
  color = "red4",
  palette = "Paired",
  return_data = F
)

Arguments

data

A SummarizedExperiment-like object. Must be compatible with assay() and colData(). The columns in assay equate to data points in the PC scatterplot.

group_var

A string or vector of strings for the grouping variable(s) to use from colData to color points. If multiple variables are specified, they are combined into a single string to make a single new variable.

pc_x

A numeric. The PC to plot on the x-axis.

pc_y

A numeric. The PC to plot on the y-axis.

ntop

A numeric. Specifies the top ntop rows ranked by decreasing variance to subset the data to prior to PCA.

center

A logical. Should the data be zero-centered prior to PCA?

scale

A logical. Should the data be scaled to unit variance prior to PCA?

equal_axes

A logical. Should the scatterplot use the same axis limits for both axes?

point_size

A numeric for the plot point size.

alpha

A numeric for the plot point alpha level.

color

A string for the color of plot points. Only used when group_var is NULL.

palette

A string for the RColorBrewer palette name to use when group_var is specified.

return_data

A logical. Should plot data be returned instead of a ggplot object?

Details

Conducts a principal component analysis (PCA) then produces a scatterplot using the user-specified eigenvectors (ie., principal components or PCs) from the eigenvector matrix. Data points can be optionally color-coded based on a user-specified variable.

Value

A ggplot object unless return_data is TRUE, then a data frame with the user-specified PCs, grouping variable, and an attribute for the percent variace explained for each user-specified PC.

See Also

prcomp SummarizedExperiment assay colData


bryancquach/omixjutsu documentation built on Jan. 29, 2023, 3:47 p.m.