Skip to contents

The plot_diversity() plots the requested clonal diversity metric

Usage

plot_diversity(
  div,
  metric = get_all_div_metrics(),
  q = 2,
  percent = 90,
  group_col = NULL,
  label_col = "Sample",
  flip = FALSE,
  facet = FALSE,
  log_scale = FALSE,
  samples = NULL,
  return_data = FALSE,
  color_scheme = NULL
)

Arguments

div

a list created by the diversity() function with diversity metrics for each sample

metric

the diversity metric to use (e.g. shannon, simpson, etc.)

q

(optional) for 'renyi' and 'hill' metrics, the order q of the diversity index

percent

(optional) for 'dXX' metric, the percentage 'XX' between 0 and 100

group_col

(optional) if supplied, a column of the metadata that will be used to group samples

label_col

(optional) labels for the samples

flip

(optional) if TRUE, flip the x and y-axes (default is FALSE)

facet

(optional) if TRUE, plot with separate facets, or sub-plots for each group (default is FALSE)

log_scale

(optional) if TRUE, use log-scale for the y-axis (default is FALSE)

return_data

(optional) if TRUE, return the data used to make the plot (default is FALSE)

Value

A list with two objects:

$plot - a ggplot object with the plot of the requested diversity metric

$data - if return_data is TRUE, the data frame used to make the plot

Details

This function can plot a variety of clonal diversity metrics for a dataset (richness, Simpson diversity index, Shannon-Wiener index, etc.). See get_all_div_metrics() for all available options. By default it return a barplot with one bar for each sample in the dataset. If a grouping column (of the metadata) is supplied, then samples will be grouped and bar heights will reflect the average diversity metric across the group, with error bars showing the standard deviation.

Examples

# example code
# data = load_tirtlseq("your_directory/")
# div = diversity(data)
# plot_diversity(div, metric = "richness")