← Về thư mục
📄 / / profiles / r-and-d / raw_evidence / OpenAI4S / skills / bioskills / bio-pathway-analysis-enrichment-visualization / references / usage-guide.md

Enrichment Visualization - Usage Guide

Overview

This skill turns an enrichment result object (an enrichResult from ORA, a gseaResult from GSEA, or a compareClusterResult) into a figure with the enrichplot package. The central decision is not which plotting function to call but how to handle gene-set REDUNDANCY: a default top-20 GO dotplot is usually one biological theme drawn twenty times, because the GO DAG and nested pathway databases guarantee that a real signal surfaces as a cluster of near-identical overlapping terms. The figure either SHOWS that redundancy as structure (emapplot/treeplot via pairwise_termsim, or EnrichmentMap) or DELETES it (simplify/REVIGO). The skill also covers keeping the NES sign for GSEA, distinguishing GeneRatio from fold enrichment, and admitting that showCategory truncates.

Prerequisites

if (!require('BiocManager', quietly = TRUE))
    install.packages('BiocManager')

BiocManager::install(c('clusterProfiler', 'enrichplot', 'org.Hs.eg.db'))
BiocManager::install(c('GOSemSim', 'ggplot2'))
install.packages(c('ggridges', 'ggarchery'))   # ridgeplot needs ggridges; goplot needs ggarchery (enrichplot Suggests-only)

Conceptual prerequisites and notes: - The input is an enrichResult / gseaResult / compareClusterResult produced by the sibling skills (go-enrichment, gsea, kegg-pathways, reactome-pathways, wikipathways), not a raw gene list. - ridgeplot() and goplot() depend on packages enrichplot only Suggests (ggridges and ggarchery); a stock install errors with the package ... is required until they are installed (above). - enrichplot 1.25.5+ moved cnetplot/emapplot/goplot to the ggtangle backend and removed several arguments (circular, colorEdge, cex_label_gene, cex_label_category, group_category). Introspect with ?cnetplot / ?emapplot and adapt; do not copy pre-2024 tutorial arguments verbatim. - emapplot and treeplot read the @termsim slot and do NOT compute it - run pairwise_termsim() first, every time. - There is no barplot method for gseaResult by design; GSEA results are signed and a bar cannot carry a sign. - The plots are offline once the objects exist; building KEGG/WikiPathways objects upstream needs internet (see those skills).

Quick Start

Tell your AI agent what you want to do: - "Make a dotplot of my GO enrichment, collapsing redundant terms first" - "Show the redundant terms as clusters with an enrichment map" - "Plot my GSEA results keeping the direction (activated vs suppressed)" - "Show a GSEA running-score plot for my top pathway"

Example Prompts

Collapsing redundancy

"My enrichGO BP result has 180 significant terms and the top-20 dotplot is full of cell-cycle synonyms. Collapse the GO-DAG redundancy with simplify(), then dotplot the top 20, and tell me how many terms survived."

"I have an enrichResult with many overlapping terms. Run pairwise_termsim and draw an enrichment map so I can see which terms are really one biological theme, and a treeplot with five named clusters."

Encoding and effect size

"Make a dotplot of my GO results ordered by fold enrichment instead of GeneRatio, and explain why the two orderings differ."

"Build a gene-concept network for my top 6 enriched terms colored by log2 fold change so I can see which genes bridge multiple terms."

GSEA plots

"Plot my gseaResult as a ridgeplot showing the leading-edge distribution per set, keeping direction, and a gseaplot2 for the single most significant pathway."

"Show the running enrichment score for my top three GSEA pathways overlaid in one panel with the stats table."

Comparison and saving

"I ran compareCluster across up- and down-regulated genes. Make a faceted dotplot comparing the two."

"Save my enrichment dotplot as a publication-quality PDF with a viridis color scale and a caption noting the total significant term count."

What the Agent Will Do

  1. Identify the object class (enrichResult, gseaResult, or compareClusterResult) since enrichplot dispatches on it.
  2. Decide the redundancy strategy: simplify()/REVIGO to delete it, or pairwise_termsim -> emapplot/treeplot to show it; never plot raw top-20 GO without a collapse step.
  3. For emapplot/treeplot, compute pairwise_termsim first (JC by default; Wang with a GOSemSimDATA object for DAG-aware GO clustering).
  4. Pick the encoding deliberately: GeneRatio vs FoldEnrichment for ORA, signed NES with a diverging scale for GSEA; never barplot a gseaResult.
  5. Generate the figure, chain ggplot2 modifiers as needed, and save with ggsave, reporting the total significant term count and the similarity method/min_edge settings.

Plot-by-Class Quick Reference

Plot Function Class Owns
Dot plot dotplot() ORA + GSEA three-channel summary; default x = GeneRatio
Bar plot barplot() ORA only unsigned count/ratio; no GSEA method
Gene-concept net cnetplot() ORA + GSEA shared genes across terms; direction by item color
Enrichment map emapplot() ORA + GSEA term clusters = redundancy shown (needs pairwise_termsim)
Tree treeplot() ORA + GSEA deterministic Ward clusters (needs pairwise_termsim)
Ridge ridgeplot() GSEA only leading-edge metric density, direction preserved
Running score gseaplot2() GSEA only ES curve + hit ticks + ranked metric
Upset upsetplot() ORA + GSEA gene-overlap combinations (boxplots for GSEA)
GO DAG goplot() GO only induced DAG subgraph
Heatmap heatplot() ORA + GSEA gene x term matrix by fold change

Tips