Skip to contents

This function visualizes recurrent mutations from a data frame. It first calculates the frequency of each mutation at specific genomic positions and then generates a lollipop plot for each group (e.g., chromosome) displaying mutations that meet a minimum recurrence threshold.

Usage

plot_lollipop(
  mutation_data,
  min_recurrence = 2,
  group_col,
  custom_palette = NULL
)

Arguments

mutation_data

A data frame containing mutation data. It must contain columns for genomic start position (start), variation_type, normalized_subtype, and a column to group by (see group_col).

min_recurrence

An integer specifying the minimum number of times a mutation must be observed at the same position to be plotted. Defaults to 2.

group_col

A string specifying the column name to group mutation_data by, typically representing chromosomes or contigs (e.g., "seqnames", "chr"). Defaults to "seqnames".

custom_palette

A named character vector for coloring the mutation subtypes. The names should match the levels in normalized_subtype. If NULL (default), a default palette is used.

Value

A list of ggplot objects. Each element of the list is a lollipop plot for a specific region (e.g., a chromosome) and is named accordingly.

Examples

if (requireNamespace("MutSeqRData", quietly = TRUE)) {
  # Example data consists of 24 mouse bone marrow DNA samples imported
  # using import_mut_data() and filtered with filter_mut as in Example 4.
  # Sequenced on TS Mouse Mutagenesis Panel. Example data is
  # retrieved from MutSeqRData, an ExperimentHub data package.
  if (requireNamespace("dplyr", quietly = TRUE) &&
    requireNamespace("ggplot2", quietly = TRUE)) {
    library(ExperimentHub)
    eh <- ExperimentHub()
    example_data <- eh[["EH9861"]]

    example_data$dose_group <- factor(example_data$dose_group,
      levels = c(
        "Control", "Low",
        "Medium", "High"
      )
    )

    # 2. Generate the plots
    plot_list <- plot_lollipop(
     mutation_data = example_data,
     min_recurrence = 2,
     group_col = "dose_group"
   )
   # 3. Display the plots for each dose group
   plot_list$Control

  }
}