Skip to contents

Produces bar, dot, or lollipop plots from ORA enrichment results (enrichR, clusterProfiler, gprofiler2, or any table with term names and p-values). Column names are auto-detected for the most common output formats; override with the *_column parameters when needed.

Usage

PlotEnrichment(
  enrichment_df,
  term_column = NULL,
  padj_column = NULL,
  gene_count_column = NULL,
  gene_ratio_column = NULL,
  group_column = NULL,
  top_n = 20,
  plot_type = "dot",
  x_by = "gene_ratio",
  color_by = "padj",
  colors = c("#B40426", "#FDDBC7", "#D1E5F0", "#3B4CC0"),
  max_term_length = 50,
  output_dir = NULL,
  object_name = "",
  subset_name = "",
  file_name = NULL,
  width = NULL,
  height = NULL,
  timestamp = FALSE
)

Arguments

enrichment_df

Data frame with ORA results, or a character path to a CSV file.

term_column

Column with term/pathway names. Auto-detected from common names ("term", "Term", "Description", etc.).

padj_column

Adjusted p-value column. Auto-detected.

gene_count_column

Column with overlap gene count. Auto-detected.

gene_ratio_column

Column with gene ratio or fold enrichment. Auto-detected; computed from gene_count_column / background if absent.

group_column

Optional column to facet by (e.g. cluster or condition). Produces one panel per group.

top_n

Maximum number of terms to show per group. Default 20.

plot_type

One of "dot" (default), "bar", or "lollipop".

x_by

What drives the x-axis (or bar length). One of "gene_ratio" (default), "gene_count", or "-log10padj".

color_by

What drives fill/color. One of "padj" (default) or "gene_count".

colors

Character vector of 2-5 colors for the gradient (low padj → high padj, i.e. significant → not). Default diverging red-blue.

max_term_length

Maximum characters for term label before wrapping. Default 50.

output_dir

Directory to save a PDF. NULL = no save.

object_name

Label prefix for output file names.

subset_name

Optional subset label.

file_name

Character or NULL. Base name (no extension) for the saved PDF. NULL (default) auto-deduces from object_name, subset_name, and plot_type.

width, height

Numeric or NULL. Override the auto-calculated PDF dimensions in inches. NULL (default) auto-sizes to the number of terms shown.

timestamp

Logical. When TRUE, append a _YYYYMMDD-HHMMSS stamp to the saved file name so repeated runs are versioned instead of overwriting the previous PDF. Default FALSE.

Value

A ggplot2 or patchwork object.