| GSEAPlotAtomic | R Documentation |
Core implementation for drawing a single GSEA (Gene Set Enrichment Analysis)
ridge plot. This is the workhorse behind the exported GSEAPlot
function — it takes a single gene set and produces a three-panel figure
showing the running enrichment score, hit positions, and the ranked list
metric.
The plot consists of three vertically stacked panels:
Running score panel — traces the running enrichment score across the ranked gene list, with a peak annotation and optional gene labels for core enrichment genes.
Hit indicator panel — marks the positions of gene set members with vertical lines, colour-coded by the rank metric value (red for positive, blue for negative).
Gene ranking panel — shows every gene's rank as a vertical segment, with annotations indicating positively and negatively correlated tails and the zero-crossing point.
The running enrichment score is computed via gsea_running_score()
using the gene_ranks and genes provided. Core enrichment genes
(from the core_enrichment column) can be labelled on the score panel
using geom_text_repel().
GSEAPlotAtomic(
data,
gene_ranks = "@gene_ranks",
gs,
genes,
metric = "p.adjust",
sample_coregenes = FALSE,
line_width = 1.5,
line_alpha = 1,
line_color = "#6BB82D",
n_coregenes = 10,
genes_label = NULL,
label_fg = "black",
label_bg = "white",
label_bg_r = 0.1,
label_size = 4,
title = NULL,
subtitle = NULL,
xlab = NULL,
ylab = NULL,
...
)
data |
A data frame. |
gene_ranks |
A named numeric vector of gene-level rank statistics, with
gene identifiers as names. Used to calculate the running enrichment score
and the ranked list metric. If a character string starting with
|
gs |
Character string specifying the |
genes |
Character vector of gene identifiers belonging to the gene set.
These are intersected with |
metric |
Character string specifying the column name in |
sample_coregenes |
Logical; if |
line_width |
Numeric specifying the line width for the running
enrichment score curve. Default is |
line_alpha |
Numeric alpha transparency for the running score line and
hit indicator bars. Default is |
line_color |
Character string specifying the colour of the running
enrichment score line. Default is |
n_coregenes |
Integer specifying the number of core enrichment genes to
label on the running score plot. Default is |
genes_label |
Character vector of specific gene names to label on the
running score plot. When provided, |
label_fg |
Character string specifying the text colour of gene labels.
Default is |
label_bg |
Character string specifying the background colour of gene
labels. Default is |
label_bg_r |
Numeric specifying the corner radius of the label
background. Default is |
label_size |
Numeric specifying the font size of the label text.
Default is |
title |
A character string specifying the title of the plot. A function can be used to generate the title based on the default title. This is useful when split_by is used and the title needs to be dynamic. |
subtitle |
A character string specifying the subtitle of the plot. |
xlab |
A character string specifying the x-axis label. |
ylab |
Character string for a right-side y-axis label (rotated 90 degrees). When provided, an extra text grob is added to the right of the assembled plot, and the plot width increases from 7.5 to 8 inches. |
... |
Additional arguments. |
A patchwork object with height and width
attributes (in inches) attached.
ggplot dispatch — selects gglogger::ggplot or
ggplot2::ggplot based on
getOption("plotthis.gglogger.enabled").
Data subsetting — if data contains multiple gene
sets (nrow > 1), it is filtered to the single row matching
gs. An error is raised if no rows match.
Gene rank resolution — resolves gene_ranks from its
"@"-prefixed attribute reference, validates that it is a named
numeric vector, and sorts it in descending order.
Title and subtitle construction — title defaults to
data$Description. subtitle is built from the NES value and
the metric column with significance stars (ns/*/**/***/****).
Plot data preparation — builds a data frame with position
(1:N), gene names, running enrichment score (via
gsea_running_score() with hits_only = FALSE), raw ranks,
and a hit indicator column.
Running score panel — renders the top panel with a red/blue
background (positive/negative score regions), a horizontal baseline at
y = 0, the running score line, and annotations for the peak
(dashed reference lines and an upward/downward triangle). Title and
subtitle are added via ggtitle().
Gene labeling — when n_coregenes > 1 or
genes_label is provided, core enrichment genes are extracted from
data$core_enrichment and labelled on the running score panel using
geom_text_repel(). Missing genes trigger a warning.
Hit indicator panel — renders the middle panel: vertical
lines (geom_linerange) at each hit position, with coloured
rectangles beneath showing the rank metric gradient (red for positive,
blue for negative).
Gene ranking panel — renders the bottom panel: vertical
segments (geom_segment) for every gene's rank, with annotations
for positively/negatively correlated tails. If both signs exist, the
zero-crossing point is marked with a dashed vertical line.
Panel assembly — the three panels are stacked vertically
via wrap_plots() with spacer panels and
proportional heights (3.5 / 1 / 1.5). When ylab is provided,
a rotated textGrob() is added to the right side and
the plot width increases from 7.5 to 8 inches.
Dimensions — height is fixed at 6.5 inches. Width is 7.5
inches (without ylab) or 8 inches (with ylab). Attributes
height and width are stored on the returned object.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.