This function 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,
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.5,
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
)
Arguments
- srt
A Seurat object containing the results of RunDEtest and RunEnrichment. If specified, enrichment results will be extracted from the Seurat object automatically. If not specified, the
res
arguments must be provided.- db
The database to use for enrichment plot. Default is "GO_BP".
- group_by
A character vector specifying the grouping variable in the Seurat object. This argument is only used if
srt
is specified.- test.use
A character vector specifying the test to be used in differential expression analysis. This argument is only used if
srt
is 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". Default is "bar".
- split_by
The splitting variable(s) for the plot. Can be "Database", "Groups", or both. Default is c("Database", "Groups") for plots.
- color_by
The variable used for coloring. Default is "Database".
- group_use
The group(s) to be used for enrichment plot. Default is NULL.
- 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
padjustCutoff
is NULL. Default is NULL.- padjustCutoff
The p-adjusted cutoff. Default is 0.05.
- topTerm
The number of top terms to display. Default is 6, or 100 if 'plot_type' is "enrichmap".
- compare_only_sig
Whether to compare only significant terms. Default is FALSE.
- topWord
The number of top words to display for wordcloud. Default is 100.
- word_type
The type of words to display in wordcloud. Options are "term" and "feature". Default is "term".
- word_size
The size range for words in wordcloud. Default is c(2, 8).
- words_excluded
Words to be excluded from the wordcloud. The default value 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 from 'igraph' package. Default is "fr".
- network_labelsize
The label size for network plot. Default is 5.
- network_blendmode
The blend mode for network plot. Default is "blend".
- network_layoutadjust
Whether to adjust the layout of the network plot to avoid overlapping words. Default is TRUE.
- network_adjscale
The scale for adjusting network plot layout. Default is 60.
- network_adjiter
The number of iterations for adjusting network plot layout. Default is 100.
- enrichmap_layout
The layout algorithm to use for enrichmap plot. Options are "fr", "kk","random", "circle", "tree", "grid", or other algorithm from 'igraph' package. Default is "fr".
- enrichmap_cluster
The clustering algorithm to use for enrichmap plot. Options are "walktrap", "fast_greedy", or other algorithm from 'igraph' package. Default is "fast_greedy".
- enrichmap_label
The label type for enrichmap plot. Options are "term" and "feature". Default is "term".
- enrichmap_labelsize
The label size for enrichmap plot. Default is 5.
- enrlichmap_nlabel
The number of labels to display for each cluster in enrichmap plot. Default is 4.
- enrichmap_show_keyword
Whether to show the keyword of terms or features in enrichmap plot. Default is FALSE.
- enrichmap_mark
The mark shape for enrichmap plot. Options are "ellipse" and "hull". Default is "ellipse".
- enrichmap_expand
The expansion factor for enrichmap plot. Default is c(0.5, 0.5).
- character_width
The maximum width of character of descriptions. Default is 50.
- lineheight
The line height for y-axis labels. Default is 0.5.
- palette
The color palette to use. Default is "Spectral".
- palcolor
Custom colors for palette. Default is NULL.
- aspect.ratio
The aspect ratio of the plot. Default is 1.
- legend.position
The position of the legend. Default is "right".
- legend.direction
The direction of the legend. Default is "vertical".
- theme_use
The theme to use for the plot. Default is "theme_scop".
- theme_args
The arguments to pass to the theme. Default is an empty list.
- combine
Whether to combine multiple plots into a single plot. Default is TRUE.
- nrow
The number of rows in the combined plot. Default is NULL, calculated based on the number of plots.
- ncol
The number of columns in the combined plot. Default is NULL, calculated based on the number of plots.
- byrow
Whether to fill the combined plot by row. Default is TRUE.
- seed
The random seed to use. Default is 11.
Examples
data(pancreas_sub)
# pancreas_sub <- RunDEtest(
# pancreas_sub,
# group_by = "CellType"
# )
pancreas_sub <- RunEnrichment(
srt = pancreas_sub,
db = c("GO_BP", "GO_CC"),
group_by = "CellType",
species = "Mus_musculus"
)
#> ℹ [2025-07-26 06:44:37] Start Enrichment
#> ℹ [2025-07-26 06:44:37] Workers: 2
#> ℹ [2025-07-26 06:44:39] Species: Mus_musculus
#> ℹ [2025-07-26 06:44:39] Loading cached db: GO_BP version:3.21.0 nterm:15445 created:2025-07-26 06:39:23.5675
#> ℹ [2025-07-26 06:45:06] Preparing database: GO_BP
#> ℹ [2025-07-26 06:45:25] Preparing database: GO_CC
#> ℹ [2025-07-26 06:45:29] Convert ID types for the database: GO_BP
#> ℹ [2025-07-26 06:45:29] Connect to the Ensembl archives...
#> ℹ [2025-07-26 06:45:29] Using the 103 version of biomart...
#> ℹ [2025-07-26 06:45:29] Connecting to the biomart...
#> ℹ [2025-07-26 06:46:29] Error in `req_perform()`:
#> ℹ [2025-07-26 06:46:29] ! Failed to perform HTTP request.
#> ℹ [2025-07-26 06:46:29] Caused by error in `curl::curl_fetch_memory()`:
#> ℹ [2025-07-26 06:46:29] ! Timeout was reached [feb2021.archive.ensembl.org]:
#> ℹ [2025-07-26 06:46:29] Operation timed out after 60000 milliseconds with 0 bytes received
#> ℹ [2025-07-26 06:46:29]
#> ℹ [2025-07-26 06:46:29] Get errors when connecting with ensembl mart...
#> ℹ [2025-07-26 06:46:30] Retrying...
#> ℹ [2025-07-26 06:46:31] Error: Your query has been redirected to http://status.ensembl.org indicating this Ensembl service is currently unavailable.
#> ℹ [2025-07-26 06:46:31] Look at ?useEnsembl for details on how to try a mirror site.
#> ℹ [2025-07-26 06:46:31]
#> ℹ [2025-07-26 06:46:31] Get errors when connecting with ensembl mart...
#> ℹ [2025-07-26 06:46:32] Retrying...
#> ℹ [2025-07-26 06:46:32] Error: Your query has been redirected to http://status.ensembl.org indicating this Ensembl service is currently unavailable.
#> ℹ [2025-07-26 06:46:32] Look at ?useEnsembl for details on how to try a mirror site.
#> ℹ [2025-07-26 06:46:32]
#> ℹ [2025-07-26 06:46:32] Get errors when connecting with ensembl mart...
#> ℹ [2025-07-26 06:46:33] Retrying...
#> ℹ [2025-07-26 06:47:33] Error in `req_perform()`:
#> ℹ [2025-07-26 06:47:33] ! Failed to perform HTTP request.
#> ℹ [2025-07-26 06:47:33] Caused by error in `curl::curl_fetch_memory()`:
#> ℹ [2025-07-26 06:47:33] ! Timeout was reached [feb2021.archive.ensembl.org]:
#> ℹ [2025-07-26 06:47:33] Operation timed out after 60002 milliseconds with 0 bytes received
#> ℹ [2025-07-26 06:47:33]
#> ℹ [2025-07-26 06:47:33] Get errors when connecting with ensembl mart...
#> ℹ [2025-07-26 06:47:34] Retrying...
#> ℹ [2025-07-26 06:47:34] Error: Your query has been redirected to http://status.ensembl.org indicating this Ensembl service is currently unavailable.
#> ℹ [2025-07-26 06:47:34] Look at ?useEnsembl for details on how to try a mirror site.
#> ℹ [2025-07-26 06:47:34]
#> ℹ [2025-07-26 06:47:34] Get errors when connecting with ensembl mart...
#> Error in log_message(out, message_type = "error"): Error: Your query has been redirected to http://status.ensembl.org
#> indicating this Ensembl service is currently unavailable. Look at ?useEnsembl
#> for details on how to try a mirror site.
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group_by = "CellType",
group_use = "Ductal",
plot_type = "bar"
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group_by = "CellType",
plot_type = "bar",
color_by = "Groups",
ncol = 2
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
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"
)
)
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group_by = "CellType",
topTerm = 3,
plot_type = "comparison"
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group_by = "CellType",
topTerm = 3,
plot_type = "comparison",
compare_only_sig = TRUE
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group_by = "CellType",
group_use = c("Ductal", "Endocrine"),
plot_type = "comparison"
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
EnrichmentPlot(
pancreas_sub,
db = c("GO_BP", "GO_CC"),
group_by = "CellType",
group_use = c("Ductal", "Endocrine"),
plot_type = "bar",
split_by = "Groups"
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
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"
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
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")
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
EnrichmentPlot(
pancreas_sub,
db = c("GO_BP", "GO_CC"),
group_by = "CellType",
group_use = c("Ductal", "Endocrine"),
plot_type = "bar",
split_by = c("Groups", "Database")
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
EnrichmentPlot(
pancreas_sub,
db = c("GO_BP", "GO_CC"),
group_by = "CellType",
plot_type = "bar",
split_by = "Database",
color_by = "Groups",
palette = "Set1"
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group_by = "CellType",
group_use = "Ductal",
plot_type = "dot",
palette = "GdRd"
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group_by = "CellType",
group_use = "Ductal",
plot_type = "lollipop",
palette = "GdRd"
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group_by = "CellType",
group_use = "Ductal",
plot_type = "wordcloud"
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group_by = "CellType",
group_use = "Ductal",
plot_type = "wordcloud",
word_type = "feature"
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group_by = "CellType",
group_use = "Ductal",
plot_type = "network"
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
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"
)
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group_by = "CellType",
group_use = "Ductal",
plot_type = "network",
network_layoutadjust = FALSE
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
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)
) |> panel_fix(height = 5)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group_by = "CellType",
group_use = "Ductal",
plot_type = "enrichmap"
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group_by = "CellType",
group_use = "Ductal",
plot_type = "enrichmap",
enrichmap_expand = c(2, 1)
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
EnrichmentPlot(
pancreas_sub,
db = "GO_BP",
group_by = "CellType",
group_use = "Ductal",
plot_type = "enrichmap",
enrichmap_show_keyword = TRUE,
character_width = 10
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
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)
) |> panel_fix(height = 4)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.
pancreas_sub <- RunEnrichment(
srt = pancreas_sub,
db = c("MP", "DO"),
group_by = "CellType",
convert_species = TRUE,
species = "Mus_musculus"
)
#> ℹ [2025-07-26 06:47:36] Start Enrichment
#> ℹ [2025-07-26 06:47:36] Workers: 2
#> ℹ [2025-07-26 06:47:36] Species: Mus_musculus
#> ℹ [2025-07-26 06:47:36] Preparing database: MP
#> ℹ [2025-07-26 06:48:31] Preparing database: DO
#> Error in decompressFile.default(filename = filename, ..., ext = ext, FUN = FUN): No such file: /tmp/Rtmpi4vzws/fileaee94f60d9d2.tsv.gz
EnrichmentPlot(
pancreas_sub,
db = c("MP", "DO"),
group_by = "CellType",
group_use = "Ductal",
ncol = 1
)
#> Error in log_message("No enrichment result found. You may perform RunEnrichment first.", message_type = "error"): No enrichment result found. You may perform RunEnrichment first.