Learn R Programming

specmine (version 4.0.0)

pca_scoresplot3D_rgl: PCA 3D scores plot using rgl

Description

Creates an interactive three-dimensional PCA scores plot using rgl.

Usage

pca_scoresplot3D_rgl(
  dataset,
  pca.result,
  column.class = NULL,
  pcas = c(1, 2, 3),
  size = 1,
  labels = FALSE
)

Value

Invisibly returns the object produced by

rgl::plot3d(); the three-dimensional plot is also drawn as a side effect.

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 sample groups.

pcas

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

size

Numeric point size passed to rgl::plot3d().

labels

Logical indicating whether sample labels should be shown.

Details

Samples are represented as points in the selected principal component space. When column.class is supplied, point colours represent the corresponding metadata groups.

Examples

Run this code
# \donttest{
if (requireNamespace("rgl", quietly = TRUE)) {
  options(rgl.useNULL = TRUE)

  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_scoresplot3D_rgl(
    dataset,
    pca.result,
    column.class = "class",
    pcas = c(1, 2, 3),
    labels = TRUE
  )
}
# }

Run the code above in your browser using DataLab