Skip to contents

Creates a scree plot from a "beta_pcoa" object (output of compute_pcoa()), showing the percentage of variance explained for the first n_axes axes.

Usage

plot_scree(pcoa_res, n_axes = NULL, type = c("bar", "line"))

Arguments

pcoa_res

A "beta_pcoa" object as returned by compute_pcoa(). Must contain an eigenvalues component (numeric vector of eigenvalues).

n_axes

Integer giving the number of axes to display. If NULL (default), the function uses min(10, length(eigenvalues)).

type

Type of scree plot to draw: "bar" (default) for a bar plot of variance explained, or "line" for a line/point plot.

Value

A ggplot2::ggplot object representing the scree plot.

Details

Percentages are computed from the positive part of the eigenvalues, i.e. pmax(eigenvalues, 0), to handle possible small negative eigenvalues from non-perfectly Euclidean distance matrices.

Styled with theme_phip().

Examples

if (FALSE) { # \dontrun{
  # pcoa_res <- compute_pcoa(dist_bc)
  plot_scree(pcoa_res)

  # More axes as line plot:
  plot_scree(pcoa_res, n_axes = 15, type = "line")
} # }