Learn R Programming

specmine (version 4.0.0)

umap_kmeans_plot2D: UMAP 2D k-means plot

Description

Creates a two-dimensional UMAP plot coloured by k-means clusters.

Usage

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

Value

A ggplot object.

Arguments

dataset

Dataset to cluster.

umap.result

Result returned by umap_analysis_dataset().

num.clusters

Number of k-means clusters.

dims

Two embedding dimensions to plot.

kmeans.result

Optional result returned by clustering().

labels

Logical indicating whether sample labels should be displayed.

bw

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

ellipses

Logical indicating whether group ellipses should be displayed.

leg.pos

Legend position.

xlim

Optional x-axis limits.

ylim

Optional y-axis limits.

Examples

Run this code
if (requireNamespace("uwot", quietly = TRUE)) {
  datamat <- matrix(
    rnorm(40),
    nrow = 5,
    dimnames = list(
      paste0("x", 1:5),
      paste0("s", 1:8)
    )
  )

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

  umap.result <- umap_analysis_dataset(
    dataset,
    n_components = 2,
    n_neighbors = 3,
    seed = 42
  )

  umap_kmeans_plot2D(
    dataset,
    umap.result,
    num.clusters = 2,
    dims = c(1, 2)
  )
}

Run the code above in your browser using DataLab