pca_kmeans_plot2D: PCA 2D k-means plot

View source: R/pca.R

pca_kmeans_plot2DR Documentation

PCA 2D k-means plot

Description

Plots PCA scores in 2D coloured by k-means cluster assignment.

Usage

pca_kmeans_plot2D(
  dataset,
  pca.result,
  num.clusters = 3,
  pcas = c(1, 2),
  kmeans.result = NULL,
  labels = FALSE,
  bw = FALSE,
  ellipses = FALSE,
  leg.pos = "right",
  xlim = NULL,
  ylim = NULL
)

Arguments

dataset

Dataset used in the PCA.

pca.result

PCA result object.

num.clusters

Number of clusters.

pcas

Principal components to plot.

kmeans.result

Optional precomputed k-means result.

labels

Logical indicating whether sample labels should be shown.

bw

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

ellipses

Logical indicating whether cluster ellipses should be drawn.

leg.pos

Legend position.

xlim

Optional x-axis limits.

ylim

Optional y-axis limits.

Value

A ggplot object.

Examples


datamat <- matrix(
  rnorm(20),
  nrow = 4,
  dimnames = list(paste0("x", 1:4), paste0("s", 1:5))
)
metadata <- data.frame(class = factor(c("A", "A", "B", "B", "A")))
dataset <- list(data = datamat, metadata = metadata)
pca_res <- pca_analysis_dataset(dataset)
pca_kmeans_plot2D(dataset, pca_res, num.clusters = 2)



specmine documentation built on Aug. 5, 2026, 5:06 p.m.