plot_rarefaction: Plot rarefaction curves

View source: R/calc-diversity.R

plot_rarefactionR Documentation

Plot rarefaction curves

Description

This method involves calculating species diversity for different sized samples generated by randomly downsampling each cluster. By default the bootstrapped 95% confidence interval will also be plotted.

Usage

plot_rarefaction(
  input,
  data_col,
  cluster_col = NULL,
  method = "richness",
  n_boots = 50,
  chain = NULL,
  chain_col = global$chain_col,
  sep = global$sep,
  plot_colors = NULL,
  plot_lvls = names(plot_colors),
  panel_nrow = NULL,
  panel_scales = "free",
  ci_alpha = 0.15,
  n_label = "legend",
  label_params = list(),
  ...
)

Arguments

input

Single cell object or data.frame containing V(D)J data. If a data.frame is provided, the cell barcodes should be stored as row names.

data_col

meta.data column containing values to use for calculating diversity

cluster_col

meta.data column containing cluster IDs to use for grouping cells when calculating clonotype abundance

method

Method to use for calculating diversity, available methods include:

  • 'richness', species richness, this is equivalent to the calculation performed by abdiv::richness()

  • 'shannon', the exponential of Shannon entropy

  • 'invsimpson', the inverse Simpson index, this is equivalent to the calculation performed by abdiv::invsimpson()

n_boots

Number of bootstrap replicates for calculating standard error, if n_boots is 0 this will be skipped.

chain

Chain to use for calculating diversity. To calculate diversity for a single chain, the column passed to the data_col argument must contain per-chain data such as CDR3 sequences. Set to NULL to include all chains.

chain_col

meta.data column containing chains for each cell

sep

Separator used for storing per-chain V(D)J data for each cell

plot_colors

Character vector containing colors for plotting

plot_lvls

Character vector containing levels for ordering

panel_nrow

The number of rows to use for arranging plot panels

panel_scales

Should scales for plot panels be fixed or free. This passes a scales specification to ggplot2::facet_wrap, can be 'fixed', 'free', 'free_x', or 'free_y'. 'fixed' will cause panels to share the same scales.

ci_alpha

Transparency to use when plotting 95% confidence interval

n_label

Location on plot where n label should be added, this can be any combination of the following:

  • 'corner', display the total number of cells plotted in the top right corner, the position of the label can be modified by passing x and y specifications with the label_params argument

  • 'legend', display the number of cells plotted for each group shown in the plot legend

  • 'none', do not display the number of cells plotted

label_params

Named list providing additional parameters to modify n label aesthetics, e.g. list(size = 4, color = "red")

...

Additional arguments to pass to ggplot2, e.g. color, fill, linetype, etc.

Value

ggplot object

See Also

calc_diversity(), plot_diversity()

Examples

# Plot rarefaction curve for each cluster
plot_rarefaction(
  vdj_sce,
  data_col    = "clonotype_id",
  cluster_col = "orig.ident",
  method      = "shannon"
)


rnabioco/AVIDtools documentation built on Oct. 28, 2023, 10:23 a.m.