This function generates various types of plots for Gene Set Enrichment Analysis (GSEA) results.
Usage
GSEAPlot(
srt,
db = "GO_BP",
group.by = NULL,
test.use = "wilcox",
res = NULL,
plot_type = c("line", "bar", "network", "enrichmap", "wordcloud", "comparison"),
group_use = NULL,
id_use = NULL,
pvalueCutoff = NULL,
padjustCutoff = 0.05,
topTerm = ifelse(plot_type == "enrichmap", 100, 6),
direction = c("pos", "neg", "both"),
compare_only_sig = FALSE,
topWord = 100,
word_type = c("term", "feature"),
word_size = c(2, 8),
words_excluded = NULL,
line_width = 1.5,
line_alpha = 1,
line_color = "#6BB82D",
n_coregene = 10,
sample_coregene = FALSE,
features_label = NULL,
label.fg = "black",
label.bg = "white",
label.bg.r = 0.1,
label.size = 4,
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 = NULL,
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 RunGSEA. If specified, GSEA results will be extracted from the Seurat object automatically. If not specified, the
resarguments 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
Seuratobject. This argument is only used ifsrtis specified.- test.use
A character vector specifying the test to be used in differential expression analysis. This argument is only used if
srtis specified.- res
Enrichment results generated by RunGSEA function. If provided, 'srt', 'test.use' and 'group.by' are ignored.
- plot_type
The type of plot to generate. Options are: "line", "comparison", "bar", "network", "enrichmap", "wordcloud". Default is
"line".- 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
padjustCutoffisNULL. Default isNULL.- padjustCutoff
The p-adjusted cutoff. Default is
0.05.- topTerm
The number of top terms to display. Default is
6, or100ifplot_typeis"enrichmap".- direction
The direction of enrichment to include in the plot. Must be one of "pos", "neg", or "both". Default is
"both".- 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. Default is
NULL, which means that the built-in words (words_excluded) will be used.- line_width
The linewidth for the line plot.
- line_alpha
The alpha value for the line plot.
- line_color
The color for the line plot.
- n_coregene
The number of core genes to label in the line plot.
- sample_coregene
Whether to randomly sample core genes for labeling in the line plot.
- features_label
A character vector of feature names to include as labels in the line plot.
- label.fg
The color of the labels.
- label.bg
The background color of the labels.
- label.bg.r
The radius of the rounding of the label's background.
- label.size
The size of the labels.
- network_layout
The layout algorithm to use for network plot. Options are
"fr","kk","random","circle","tree","grid", or other algorithm fromigraphpackage. 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 fromigraphpackage. Default is"fr".- enrichmap_cluster
The clustering algorithm to use for enrichmap plot. Options are
"walktrap","fast_greedy", or other algorithm fromigraphpackage. 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.7.- palette
Color palette name. Available palettes can be found in thisplot::show_palettes. Default is
"Spectral".- palcolor
Custom colors used to create a color palette. Default is
NULL.- aspect.ratio
Aspect ratio of the panel. Default is
1.- legend.position
The position of legends, one of
"none","left","right","bottom","top". Default is"right".- legend.direction
The direction of the legend in the plot. Can be one of
"vertical"or"horizontal".- theme_use
Theme used. Can be a character string or a theme function. Default is
"theme_scop".- theme_args
Other arguments passed to the
theme_use. Default islist().- combine
Combine plots into a single
patchworkobject. IfFALSE, return a list of ggplot objects.- nrow
Number of rows in the combined plot. Default is
NULL, which means determined automatically based on the number of plots.- ncol
Number of columns in the combined plot. Default is
NULL, which means determined automatically based on the number of plots.- byrow
Whether to arrange the plots by row in the combined plot. Default is
TRUE.- seed
Random seed for reproducibility. Default is
11.
Examples
data(pancreas_sub)
pancreas_sub <- standard_scop(pancreas_sub)
#> ℹ [2026-05-14 06:12:39] Start standard processing workflow...
#> ℹ [2026-05-14 06:12:40] Checking a list of <Seurat>...
#> ! [2026-05-14 06:12:40] Data 1/1 of the `srt_list` is "unknown"
#> ℹ [2026-05-14 06:12:40] Perform `NormalizeData()` with `normalization.method = 'LogNormalize'` on 1/1 of `srt_list`...
#> ℹ [2026-05-14 06:12:42] Perform `Seurat::FindVariableFeatures()` on 1/1 of `srt_list`...
#> ℹ [2026-05-14 06:12:42] Use the separate HVF from `srt_list`
#> ℹ [2026-05-14 06:12:42] Number of available HVF: 2000
#> ℹ [2026-05-14 06:12:43] Finished check
#> ℹ [2026-05-14 06:12:43] Perform `Seurat::ScaleData()`
#> ℹ [2026-05-14 06:12:43] Perform pca linear dimension reduction
#> ℹ [2026-05-14 06:12:43] Use stored estimated dimensions 1:20 for Standardpca
#> ℹ [2026-05-14 06:12:44] Perform `Seurat::FindClusters()` with `cluster_algorithm = 'louvain'` and `cluster_resolution = 0.6`
#> ℹ [2026-05-14 06:12:44] Reorder clusters...
#> ℹ [2026-05-14 06:12:44] Skip `log1p()` because `layer = data` is not "counts"
#> ℹ [2026-05-14 06:12:44] Perform umap nonlinear dimension reduction
#> ℹ [2026-05-14 06:12:44] Perform umap nonlinear dimension reduction using Standardpca (1:20)
#> ℹ [2026-05-14 06:12:49] Perform umap nonlinear dimension reduction using Standardpca (1:20)
#> ✔ [2026-05-14 06:12:54] Standard processing workflow completed
pancreas_sub <- RunDEtest(
pancreas_sub,
group.by = "CellType"
)
#> ℹ [2026-05-14 06:12:54] Data type is log-normalized
#> ℹ [2026-05-14 06:12:54] Start differential expression test
#> ℹ [2026-05-14 06:12:54] Find all markers(wilcox) among [1] 5 groups...
#> ℹ [2026-05-14 06:12:54] Using 1 core
#> ⠙ [2026-05-14 06:12:54] Running for Ductal [1/5] ■■ 20% | ETA: 1s
#> ✔ [2026-05-14 06:12:54] Completed 5 tasks in 951ms
#>
#> ℹ [2026-05-14 06:12:54] Building results
#> ✔ [2026-05-14 06:12:55] Differential expression test completed
pancreas_sub <- RunGSEA(
pancreas_sub,
group.by = "CellType",
db = "GO_BP",
species = "Mus_musculus"
)
#> ℹ [2026-05-14 06:12:55] Start GSEA analysis
#> ! [2026-05-14 06:12:55] All values in the `geneScore` are greater than zero. Set scoreType = 'pos'
#> ℹ [2026-05-14 06:12:55] Species: "Mus_musculus"
#> ℹ [2026-05-14 06:12:55] Loading cached: GO_BP version: 3.23.0 nterm:14957 created: 2026-05-14 06:04:39
#> ℹ [2026-05-14 06:12:56] Using 1 core
#> Registered S3 methods overwritten by 'callr':
#> method from
#> format.callr_status_error
#> print.callr_status_error
#> Registered S3 method overwritten by 'ggtree':
#> method from
#> fortify.igraph ggnetwork
#> ⠙ [2026-05-14 06:12:56] Running for 1 [1/5] ■■ 20% | ETA: 33s
#> ⠹ [2026-05-14 06:12:56] Running for 2 [2/5] ■■■■ 40% | ETA: 17s
#> ⠸ [2026-05-14 06:12:56] Running for 3 [3/5] ■■■■■■ 60% | ETA: 11s
#> ⠼ [2026-05-14 06:12:56] Running for 4 [4/5] ■■■■■■■■ 80% | ETA: 5s
#> ✔ [2026-05-14 06:12:56] Completed 5 tasks in 22.5s
#>
#> ℹ [2026-05-14 06:12:56] Building results
#> ✔ [2026-05-14 06:13:19] GSEA analysis done
GSEAPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal"
)
p1 <- GSEAPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
id_use = "GO:0006412"
)
#> Error in `.rowNamesDF<-`(x, value = value): missing values in 'row.names' are not allowed
p1
#> Error: object 'p1' not found
thisplot::panel_fix_overall(p1, height = 6)
#> Error: object 'p1' not found
GSEAPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
topTerm = 3,
plot_type = "comparison"
)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's alpha values.
#> Warning: Removed 9786 rows containing missing values or values outside the scale range
#> (`geom_point()`).
GSEAPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
topTerm = 3,
plot_type = "comparison",
direction = "pos"
)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's alpha values.
#> Warning: Removed 9786 rows containing missing values or values outside the scale range
#> (`geom_point()`).
GSEAPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
topTerm = 3,
plot_type = "comparison",
compare_only_sig = TRUE
)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's alpha values.
#> Warning: Removed 9786 rows containing missing values or values outside the scale range
#> (`geom_point()`).
GSEAPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
plot_type = "bar"
)
#> Error in `.rowNamesDF<-`(x, value = value): missing values in 'row.names' are not allowed
GSEAPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
plot_type = "bar",
direction = "both"
)
#> Error in `.rowNamesDF<-`(x, value = value): missing values in 'row.names' are not allowed
GSEAPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "bar",
topTerm = 20,
direction = "both",
palcolor = c("red3", "steelblue")
)
GSEAPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "network"
)
#> ✔ [2026-05-14 06:13:22] shadowtext installed successfully
GSEAPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "enrichmap"
)
GSEAPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "wordcloud"
)
GSEAPlot(
pancreas_sub,
db = "GO_BP",
group.by = "CellType",
group_use = "Ductal",
plot_type = "wordcloud",
word_type = "feature"
)