Generates various types of plots for enrichment (over-representation) analysis.
Usage
EnrichmentPlot(
srt,
db = "GO_BP",
group.by = NULL,
test.use = "wilcox",
res = NULL,
plot_type = c("bar", "dot", "lollipop", "network", "enrichmap", "wordcloud",
"comparison"),
split_by = c("Database", "Groups"),
color_by = "Database",
group_use = NULL,
id_use = NULL,
pvalueCutoff = NULL,
padjustCutoff = 0.05,
score_col = NULL,
scoreCutoff = NULL,
score_label = "Score",
topTerm = ifelse(plot_type == "enrichmap", 100, 6),
compare_only_sig = FALSE,
topWord = 100,
word_type = c("term", "feature"),
word_size = c(2, 8),
words_excluded = NULL,
network_layout = "fr",
network_labelsize = 5,
network_blendmode = "blend",
network_layoutadjust = TRUE,
network_adjscale = 60,
network_adjiter = 100,
enrichmap_layout = "fr",
enrichmap_cluster = "fast_greedy",
enrichmap_label = c("term", "feature"),
enrichmap_labelsize = 5,
enrlichmap_nlabel = 4,
enrichmap_show_keyword = FALSE,
enrichmap_mark = c("ellipse", "hull"),
enrichmap_expand = c(0.5, 0.5),
character_width = 50,
lineheight = 0.7,
palette = "Spectral",
palcolor = NULL,
aspect.ratio = 1,
legend.position = "right",
legend.direction = "vertical",
theme_use = "theme_scop",
theme_args = list(),
combine = TRUE,
nrow = NULL,
ncol = NULL,
byrow = TRUE,
seed = 11,
verbose = TRUE
)Arguments
- srt
A Seurat object containing the results of RunDEtest and RunEnrichment. If specified, enrichment results will be extracted from the
Seuratobject automatically. If not specified, theresarguments must be provided.- db
The database to use for enrichment plot.
- group.by
Grouping variable in the
Seuratobject. This argument is only used ifsrtis specified.- test.use
Test to be used in differential expression analysis. This argument is only used if
srtis specified.- res
Enrichment results generated by RunEnrichment function. If provided, 'srt', 'test.use' and 'group.by' are ignored.
- plot_type
The type of plot to generate. Options are:
"bar","dot","lollipop","network","enrichmap","wordcloud","comparison".- split_by
The splitting variable(s) for the plot. Can be
"Database","Groups", or both. Default isc("Database", "Groups")for plots.- color_by
The variable used for coloring.
- group_use
The group(s) to be used for enrichment plot.
- id_use
List of IDs to be used to display specific terms in the enrichment plot. Default value is
NULL.- pvalueCutoff
The p-value cutoff. Only work when
padjustCutoffisNULL.- padjustCutoff
The p-adjusted cutoff.
- score_col
Optional numeric score column. When supplied, terms are ranked and weighted by the absolute score and no p-value semantics are used. This is intended for activity or importance results such as pathway scores.
- scoreCutoff
Optional minimum absolute score used with
score_col.- score_label
Legend label used with
score_col.- topTerm
The number of top terms to display. Default is
6, or100ifplot_typeis"enrichmap".- compare_only_sig
Whether to compare only significant terms.
- topWord
The number of top words to display for wordcloud.
- word_type
The type of words to display in wordcloud. Options are
"term"and"feature".- word_size
The size range for words in wordcloud.
- words_excluded
Words to be excluded from the wordcloud. Default is
NULL, which means that the built-in words (words_excluded) will be used.- network_layout
The layout algorithm to use for network plot. Options are
"fr","kk","random","circle","tree","grid", or other algorithm fromigraphpackage.- network_labelsize
The label size for network plot.
- network_blendmode
The blend mode for network plot.
- network_layoutadjust
Whether to adjust the layout of the network plot to avoid overlapping words.
- network_adjscale
The scale for adjusting network plot layout.
- network_adjiter
The number of iterations for adjusting network plot layout.
- enrichmap_layout
The layout algorithm to use for enrichmap plot. Options are
"fr","kk","random","circle","tree","grid", or other algorithm fromigraphpackage.- enrichmap_cluster
The clustering algorithm to use for enrichmap plot. Options are
"walktrap","fast_greedy", or other algorithm fromigraphpackage.- enrichmap_label
The label type for enrichmap plot. Options are
"term"and"feature".- enrichmap_labelsize
The label size for enrichmap plot.
- enrlichmap_nlabel
The number of labels to display for each cluster in enrichmap plot.
- enrichmap_show_keyword
Whether to show the keyword of terms or features in enrichmap plot.
- enrichmap_mark
The mark shape for enrichmap plot. Options are
"ellipse"and"hull".- enrichmap_expand
The expansion factor for enrichmap plot.
- character_width
The maximum width of character of descriptions.
- lineheight
The line height for y-axis labels.
- palette
Color palette name. Available palettes can be found in thisplot::show_palettes.
- palcolor
Custom colors used to create a color palette.
- aspect.ratio
Panel aspect ratio.
- legend.position
Legend placement (
"none","left","right","bottom","top"), direction, and title.legend.title = NULLuses the group name.- legend.direction
Legend direction:
"horizontal"or"vertical".- theme_use, theme_args
Theme name or function, plus extra theme arguments.
- combine, nrow, ncol, byrow
Combine plots with patchwork.
combine = FALSEreturns a list of ggplots.- seed
Random seed.
- verbose
Whether to print messages.
Examples
data(pancreas_sub)
pancreas_sub <- RunStandardWorkflow(pancreas_sub)
#> ℹ [2026-08-30 04:24:33] Start standard processing workflow...
#> ℹ [2026-08-30 04:24:33] Checking a list of <Seurat>...
#> ! [2026-08-30 04:24:33] Data 1/1 of the `srt_list` is "unknown"
#> Warning: Data 1/1 of the `srt_list` is "unknown"
#> ℹ [2026-08-30 04:24:33] Perform `NormalizeData()` with `normalization.method = 'LogNormalize'` on 1/1 of `srt_list`...
#> ℹ [2026-08-30 04:24:33] Perform `FindVariableFeatures()` on 1/1 of `srt_list`...
#> ℹ [2026-08-30 04:24:33] Use the separate HVF from `srt_list`
#> ℹ [2026-08-30 04:24:33] Number of available HVF: 2000
#> ℹ [2026-08-30 04:24:34] Finished check
#> ℹ [2026-08-30 04:24:34] Perform `ScaleData()`
#> ℹ [2026-08-30 04:24:34] Perform pca linear dimension reduction
#> ℹ [2026-08-30 04:24:34] Use stored estimated dimensions 1:23 for Standardpca
#> ℹ [2026-08-30 04:24:34] Perform `Seurat::FindClusters()` with `cluster_algorithm = 'louvain'` and `cluster_resolution = 0.6`
#> ℹ [2026-08-30 04:24:34] Reorder clusters...
#> ℹ [2026-08-30 04:24:34] Skip `log1p()` because `layer = data` is not "counts"
#> ℹ [2026-08-30 04:24:34] Perform umap nonlinear dimension reduction
#> ✔ [2026-08-30 04:24:41] Standard processing workflow completed
pancreas_sub <- RunDEtest(
pancreas_sub,
group.by = "CellType"
)
#> ℹ [2026-08-30 04:24:42] Data type is log-normalized
#> ℹ [2026-08-30 04:24:42] Start differential expression test
#> ℹ [2026-08-30 04:24:42] Find all markers(wilcox) among [1] 5 groups...
#> ✔ [2026-08-30 04:24:42] Differential expression test completed
pancreas_sub <- RunEnrichment(
pancreas_sub,
db = c("GO_BP", "GO_CC"),
group.by = "CellType",
species = "Mus_musculus"
)
#> ℹ [2026-08-30 04:24:42] Start Enrichment analysis
#> ℹ [2026-08-30 04:24:42] Species: "Mus_musculus"
#> ℹ [2026-08-30 04:24:42] Loading cached: GO_BP version: 3.23.0 nterm:14957 created: 2026-08-30 04:14:47
#> ℹ [2026-08-30 04:25:09] Preparing database: GO_BP
#> ℹ [2026-08-30 04:25:17] Preparing database: GO_CC
#> ℹ [2026-08-30 04:25:21] Convert ID types for the GO_BP database
#> ℹ [2026-08-30 04:25:21] Converted ID types using local annotation package org.Mm.eg.db
#> ℹ [2026-08-30 04:25:23] Convert ID types for the GO_CC database
#> ℹ [2026-08-30 04:25:23] Converted ID types using local annotation package org.Mm.eg.db
#> ℹ [2026-08-30 04:25:24] Permform enrichment...
#> ℹ [2026-08-30 04:25:25] Using 1 core
#> ⠙ [2026-08-30 04:25:25] Running for 1 [1/10] ■ 10% | ETA: 13s
#> ⠹ [2026-08-30 04:25:25] Running for 2 [2/10] ■■ 20% | ETA: 11s
#> ⠸ [2026-08-30 04:25:25] Running for 4 [4/10] ■■■■ 40% | ETA: 9s
#> ⠼ [2026-08-30 04:25:25] Running for 9 [9/10] ■■■■■■■■■ 90% | ETA: 1s
#> ✔ [2026-08-30 04:25:25] Completed 10 tasks in 9.2s
#>
#> ℹ [2026-08-30 04:25:25] Building results
#> ✔ [2026-08-30 04:25:34] Enrichment analysis done
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "bar"
)
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
plot_type = "bar",
color_by = "Groups",
ncol = 2
)
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
plot_type = "bar",
id_use = list(
"Ductal" = c(
"GO:0002181", "GO:0045787",
"GO:0006260", "GO:0050679"
),
"Ngn3-low-EP" = c(
"GO:0050678", "GO:0051101",
"GO:0072091", "GO:0006631"
),
"Ngn3-high-EP" = c(
"GO:0035270", "GO:0030325",
"GO:0008637", "GO:0030856"
),
"Pre-endocrine" = c(
"GO:0090276", "GO:0031018",
"GO:0030073", "GO:1903532"
)
)
)
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
topTerm = 3,
plot_type = "comparison"
)
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
topTerm = 3,
plot_type = "comparison",
compare_only_sig = TRUE
)
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = c("Ductal", "Endocrine"),
plot_type = "comparison"
)
EnrichmentPlot(
pancreas_sub,
db = c("GO_BP", "GO_CC"),
group.by = "CellType",
group_use = c("Ductal", "Endocrine"),
plot_type = "bar",
split_by = "Groups"
)
EnrichmentPlot(
pancreas_sub,
db = c("GO_BP", "GO_CC"),
group.by = "CellType",
group_use = c("Ductal", "Endocrine"),
plot_type = "bar",
split_by = "Database",
color_by = "Groups"
)
EnrichmentPlot(
pancreas_sub,
db = c("GO_BP", "GO_CC"),
group.by = "CellType",
group_use = c("Ductal", "Endocrine"),
plot_type = "bar",
split_by = c("Database", "Groups")
)
EnrichmentPlot(
pancreas_sub,
db = c("GO_BP", "GO_CC"),
group.by = "CellType",
plot_type = "bar",
split_by = "Database",
color_by = "Groups",
palette = "Set1"
)
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "dot",
palette = "GdRd"
)
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "lollipop",
palette = "GdRd"
)
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "wordcloud"
)
#> Warning: One word could not fit on page. It has been removed.
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "wordcloud",
word_type = "feature"
)
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "network"
)
#> Found more than one class "dist" in cache; using the first, from namespace 'spam'
#> Also defined by ‘BiocGenerics’
#> Found more than one class "dist" in cache; using the first, from namespace 'spam'
#> Also defined by ‘BiocGenerics’
#> ◌ [2026-08-30 04:25:53] Installing 1 R packages...
#>
#> → Package library at /home/runner/work/_temp/Library.
#> → Will install 1 package.
#> → The package (0 B) is cached.
#> + shadowtext 0.1.6
#> ✔ All system requirements are already installed.
#>
#> ℹ No downloads are needed, 1 pkg is cached
#> ✔ Got shadowtext 0.1.6 (x86_64-pc-linux-gnu-ubuntu-24.04) (243.63 kB)
#> ℹ Installing system requirements
#> ℹ Executing `sudo sh -c apt-get -y update`
#> Get:1 file:/etc/apt/apt-mirrors.txt Mirrorlist [144 B]
#> Hit:2 http://azure.archive.ubuntu.com/ubuntu noble InRelease
#> Hit:3 http://azure.archive.ubuntu.com/ubuntu noble-updates InRelease
#> Hit:4 http://azure.archive.ubuntu.com/ubuntu noble-backports InRelease
#> Hit:5 http://azure.archive.ubuntu.com/ubuntu noble-security InRelease
#> Hit:6 https://packages.microsoft.com/repos/azure-cli noble InRelease
#> Hit:7 https://packages.microsoft.com/ubuntu/24.04/prod noble InRelease
#> Hit:8 https://dl.google.com/linux/chrome-stable/deb stable InRelease
#> Reading package lists...
#> ℹ Executing `sudo sh -c apt-get -y install cmake make libuv1-dev libcairo2-dev libfontconfig1-dev libfreetype6-dev libpng-dev pandoc`
#> Reading package lists...
#> Building dependency tree...
#> Reading state information...
#> cmake is already the newest version (3.28.3-1build7).
#> make is already the newest version (4.3-4.1build2).
#> libuv1-dev is already the newest version (1.48.0-1.1build1).
#> libcairo2-dev is already the newest version (1.18.0-3build1).
#> libfontconfig1-dev is already the newest version (2.15.0-1.1ubuntu2).
#> libfreetype-dev is already the newest version (2.13.2+dfsg-1ubuntu0.1).
#> libpng-dev is already the newest version (1.6.43-5ubuntu0.6).
#> pandoc is already the newest version (3.1.3+ds-2).
#> 0 upgraded, 0 newly installed, 0 to remove and 26 not upgraded.
#> ✔ Installed shadowtext 0.1.6 (1s)
#> ✔ 1 pkg + 55 deps: kept 54, added 1, dld 1 (243.63 kB) [4.7s]
#> ✔ [2026-08-30 04:25:58] shadowtext installed successfully
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "network",
id_use = c(
"GO:0050678",
"GO:0035270",
"GO:0090276",
"GO:0030073"
)
)
#> ✔ [2026-08-30 04:25:59] shadowtext installed successfully
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "network",
network_layoutadjust = FALSE
)
#> ✔ [2026-08-30 04:25:59] shadowtext installed successfully
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "network",
topTerm = 4,
network_blendmode = "average",
theme_use = "theme_blank",
theme_args = list(add_coord = FALSE)
) |> thisplot::panel_fix(height = 5)
#> ✔ [2026-08-30 04:26:01] shadowtext installed successfully
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "enrichmap"
)
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "enrichmap",
enrichmap_expand = c(2, 1)
)
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "enrichmap",
enrichmap_show_keyword = TRUE,
character_width = 10
)
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "enrichmap",
topTerm = 200,
enrichmap_mark = "hull",
enrichmap_label = "feature",
enrlichmap_nlabel = 3,
character_width = 10,
theme_use = "theme_blank",
theme_args = list(add_coord = FALSE)
) |> thisplot::panel_fix(height = 4)
pancreas_sub <- RunEnrichment(
pancreas_sub,
db = c("MP", "DO"),
group.by = "CellType",
convert_species = TRUE,
species = "Mus_musculus"
)
#> ℹ [2026-08-30 04:26:04] Start Enrichment analysis
#> ℹ [2026-08-30 04:26:04] Species: "Mus_musculus"
#> ℹ [2026-08-30 04:26:04] Preparing MP database
#> ℹ [2026-08-30 04:26:18] Preparing DO database
#> ℹ [2026-08-30 04:26:22] Permform enrichment...
#> ℹ [2026-08-30 04:26:22] Using 1 core
#> ⠙ [2026-08-30 04:26:22] Running for 1 [1/10] ■ 10% | ETA: 3s
#> ✔ [2026-08-30 04:26:22] Completed 10 tasks in 1.9s
#>
#> ℹ [2026-08-30 04:26:22] Building results
#> ✔ [2026-08-30 04:26:24] Enrichment analysis done
EnrichmentPlot(
pancreas_sub,
db = c("MP", "DO"),
group.by = "CellType",
group_use = "Ductal",
ncol = 1
)