plot_clone_frequency: Plot clonotype frequency

View source: R/calc-frequency.R

plot_clone_frequencyR Documentation

Plot clonotype frequency

Description

Plot clonotype frequency

Usage

plot_clone_frequency(
  input,
  data_col = global$clonotype_col,
  cluster_col = NULL,
  group_col = NULL,
  clones = NULL,
  method = "bar",
  units = "percent",
  plot_colors = NULL,
  plot_lvls = names(plot_colors),
  trans = "identity",
  panel_nrow = NULL,
  panel_scales = "free_x",
  n_label = "corner",
  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 clonotype IDs to use for calculating clonotype abundance

cluster_col

meta.data column containing cluster IDs to use for grouping cells when calculating clonotype frequencies. Clonotypes will be plotted separately for each cluster.

group_col

meta.data column to use for grouping cluster IDs present in cluster_col. This is useful when there are multiple replicates or patients for each treatment condition. This is only applicable when method is 'line'.

clones

An integer specifying the number of clonotypes to show, or a vector giving the names of clonotypes to include. If method is set to 'line', this will specify the clonotypes to label.

method

Method to use for plotting, possible values include:

  • 'bar', create a bargraph

  • 'line', create a rank-abundance plot

units

Units to plot on the y-axis, either 'frequency' or 'percent'

plot_colors

Character vector containing colors for plotting

plot_lvls

Levels to use for ordering clusters

trans

Transformation to use for plotting data, e.g. 'log10'. By default values are not transformed, refer to ggplot2::continuous_scale()

panel_nrow

The number of rows to use for arranging plot panels, use this when separate bar graphs are created for each cell cluster

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. Use this when separate bar graphs are created for each cell cluster.

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 clonotype and n label aesthetics, e.g. list(size = 4, color = "red")

...

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

Value

ggplot object

See Also

calc_frequency(), plot_frequency()

Examples

# Plot clonotype abundance using all cells
plot_clone_frequency(
  vdj_sce,
  data_col = "clonotype_id"
)

# Plot clonotype abundance separately for each cell cluster
plot_clone_frequency(
  vdj_sce,
  cluster_col = "orig.ident"
)

# Plot the frequency of each clonotype instead of percentage
plot_clone_frequency(
  vdj_sce,
  cluster_col = "orig.ident",
  units = "frequency"
)

# Specify colors to use for each cell cluster
plot_clone_frequency(
  vdj_sce,
  cluster_col = "orig.ident",
  plot_colors = c(avid_1 = "blue", avid_2 = "red")
)

# Specify order to use for plotting cell clusters
plot_clone_frequency(
  vdj_sce,
  cluster_col = "orig.ident",
  plot_lvls = c("avid_2", "avid_1")
)

# Specify the number of top clonotypes to plot
plot_clone_frequency(
  vdj_sce,
  clones = 5
)

#' # Create line graph
# use clones to set the number of clonotypes to label
plot_clone_frequency(
  vdj_sce,
  cluster_col = "orig.ident",
  method = "line",
  clones = 3
)


rnabioco/djvdj documentation built on Oct. 24, 2023, 7:33 p.m.