Learn R Programming

specmine (version 4.0.0)

pca_plot_3d: Auto-exported function: pca_plot_3d

Description

Draw a 3D PCA scatter plot.

Usage

pca_plot_3d(
  dataset,
  model,
  var.class,
  pcas = 1:3,
  colors = NULL,
  legend.place = "topright",
  ...
)

Value

A 3D scatter plot of the selected principal components, drawn for its side effects.

Arguments

dataset

A dataset object containing metadata.

model

A PCA result object containing component scores.

var.class

The metadata variable used to define classes.

pcas

A length-3 integer vector indicating which principal components to plot.

colors

Optional vector of colors used for the classes.

legend.place

Position of the legend.

...

Additional arguments passed to legend().

Examples

Run this code
if (FALSE) {
datamat <- matrix(
  rnorm(24),
  nrow = 4,
  dimnames = list(paste0("v", 1:4), paste0("s", 1:6))
)
metadata <- data.frame(class = factor(c("A", "A", "A", "B", "B", "B")))
dataset <- list(data = datamat, metadata = metadata)
pca_model <- list(scores = prcomp(t(datamat))$x)
pca_plot_3d(dataset, pca_model, "class")
}

Run the code above in your browser using DataLab