Generates various types of plots for Gene Set Enrichment Analysis (GSEA) results.
Usage
GSEAPlot(
object = NULL,
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,
enrichmap_nlabel = 4,
enrlichmap_nlabel = NULL,
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,
verbose = TRUE,
srt = NULL
)Arguments
- object
A
Seuratobject containing the results of RunDEtest and RunGSEA. If specified, GSEA results will be extracted from the Seurat object 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 ifobjectis specified.NULL(the default) selects the results that RunGSEA stored for custom gene sets or custom cell groups, which are keyed as"custom".- test.use
Test to be used in differential expression analysis. This argument is only used if
objectis specified.- res
Enrichment results generated by RunGSEA function. If provided, 'object', 'test.use' and 'group.by' are ignored.
- plot_type
The type of plot to generate. Options are: "line", "comparison", "bar", "network", "enrichmap", "wordcloud".
- 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.
- 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".
- 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.- 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
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.- 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.
- enrichmap_nlabel
The number of labels to display for each cluster in enrichmap plot.
- enrlichmap_nlabel
Deprecated. Please use
enrichmap_nlabelinstead.- 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.
- srt
Deprecated alias for
object; supply exactly one of the two. It will be removed in scop 1.0.0.
Examples
term2gene <- data.frame(
Term = c(rep("Endocrine markers", 5), rep("Ductal markers", 5)),
symbol = c("INS", "GCG", "SST", "IAPP", "PCSK1", "KRT19", "SOX9", "MUC1", "CFTR", "KRT7")
)
genes <- unique(term2gene$symbol)
scores <- seq_along(genes)
names(scores) <- genes
gsea_out <- RunGSEA(
geneID = genes,
geneScore = scores,
geneID_groups = rep("Cluster1", length(genes)),
TERM2GENE = term2gene,
minGSSize = 2
)
#> ℹ [2026-10-11 22:57:05] Start GSEA analysis
#> ! [2026-10-11 22:57:05] All values in the `geneScore` are greater than zero. Set scoreType = 'pos'
#> ℹ [2026-10-11 22:57:05] Preparing custom GSEA database from `TERM2GENE`/`TERM2NAME` ...
#> ℹ [2026-10-11 22:57:05] Prepared 10 ranked gene rows after ID mapping.
#> ℹ [2026-10-11 22:57:05] Running GSEA for 1 group/database combination(s) ...
#> ℹ [2026-10-11 22:57:05] Running GSEA: group "Cluster1", database "custom", genes 10 ...
#> Registered S3 method overwritten by 'ggtree':
#> method from
#> fortify.igraph ggnetwork
#> Error in gsea(geneList = geneList, gene_sets = geneSets, weight = weight, minGSSize = minGSSize, maxGSSize = maxGSSize, nPerm = nPerm, exponent = exponent, method = method, adaptive = adaptive, minPerm = minPerm, maxPerm = maxPerm, pvalThreshold = pvalThreshold, seed = seed, verbose = verbose, ...): unused argument (by = "fgsea")
GSEAPlot(res = gsea_out, db = "custom", plot_type = "comparison")
#> Error: object 'gsea_out' not found
GSEAPlot(res = gsea_out, db = "custom", plot_type = "bar")
#> Error: object 'gsea_out' not found