Learn R Programming

specmine (version 4.0.0)

pca_scoresplot2D: PCA 2D scores plot

Description

Creates a two-dimensional PCA scores plot.

Usage

pca_scoresplot2D(
  dataset,
  pca.result,
  column.class = NULL,
  pcas = c(1, 2),
  labels = FALSE,
  ellipses = FALSE,
  bw = FALSE,
  pallette = 2,
  leg.pos = "right",
  xlim = NULL,
  ylim = NULL
)

Value

A ggplot object containing the PCA scores plot. The plotted points represent samples, and their coordinates are the selected PCA scores. When column.class is supplied, point colours or shapes represent the corresponding metadata groups.

Arguments

dataset

Dataset used in the PCA. Its data matrix must contain variables in rows and samples in columns.

pca.result

PCA result object of class prcomp or princomp.

column.class

Optional metadata column used for colouring or grouping samples.

pcas

Integer vector of length two specifying the principal components to plot.

labels

Logical indicating whether sample labels should be shown.

ellipses

Logical indicating whether group ellipses should be drawn.

bw

Logical indicating whether a black-and-white style should be used.

pallette

RColorBrewer palette identifier. The argument name pallette is retained for compatibility with previous versions.

leg.pos

Legend position.

xlim

Optional numeric vector of length two defining the x-axis limits.

ylim

Optional numeric vector of length two defining the y-axis limits.

Details

The function accepts results from pca_analysis_dataset(), stats::prcomp() or stats::princomp().

Examples

Run this code
datamat <- matrix(
  rnorm(40),
  nrow = 4,
  ncol = 10,
  dimnames = list(
    paste0("feature", 1:4),
    paste0("sample", 1:10)
  )
)

dataset <- list(
  data = datamat,
  metadata = data.frame(
    class = factor(rep(c("A", "B"), each = 5))
  )
)

pca.result <- pca_analysis_dataset(dataset)

pca_scoresplot2D(
  dataset,
  pca.result,
  column.class = "class",
  pcas = c(1, 2),
  labels = TRUE
)

Run the code above in your browser using DataLab