12 Plot FCS-GSEA

GSEA analysis returns a list result, and there are two ways of visualization:

  • Directly pass the list to plotGSEA, which enables 5 types (classic pathway plot, volcano plot, multi-pathway plot, ridge plot and two-side bar plot).

  • Extract the analysis result (e.g. gse_list$gsea_df) then pass it to plotEnrich, which enables 8 types (geneheat, genechord, wordcloud, upset, network, gomap, goheat, gotangram).

12.1 Get GSEA result

For more details, please refer to chapter 9

# 1st step: prepare pre-ranked gene list
data(geneList, package = "genekitr")
head(geneList)
##       948      1638    158471     10610      6947 100133941 
##  5.780170  5.633027  4.683610  3.875120  3.357670  3.322533
# 2nd step: prepare gene set
gs <- geneset::getMsigdb(org = "human",category = 'H')

# 3rd step: GSEA analysis
gse <- genGSEA(genelist = geneList, geneset = gs)

12.2 Classic Pathway Plot

The running enrichment score of a gene set is drawn as classic pathway plot lines. The function walks down the ranked gene list. The vertical lines in the middle show the location of gene set members.

If users want to show specific pathways or genes, just pass them to the corresponding parameters: - show_pathway: IDs in the GSEA result - show_gene: IDs in the GSEA result

pathways <- c("HALLMARK_P53_PATHWAY", "HALLMARK_GLYCOLYSIS", "HALLMARK_DNA_REPAIR")
genes <- c("MET", "TP53", "PMM2")
plotGSEA(gse, plot_type = "classic", show_pathway = pathways, show_gene = genes)
Classic pathway plot of GSEA.

Figure 12.1: Classic pathway plot of GSEA.

12.3 Volcano Pathway Plot

In this plot, the degree of enrichment is indicated by a normalized enrichment score, or NES.

Slightly different from the DEG volcano plot, the x-axis here represents NES, which corrects for enrichment score differences among gene sets.

A significant positive NES value indicates that members of the gene set tend to appear at the top of the ranked data (e.g. fold change of DEG), and a significant negative NES indicates the opposite.

By default, the top N pathways are shown. If users want to show a specific pathway, also pass the argument to show_pathway.

library(patchwork)
pathways <- c("HALLMARK_P53_PATHWAY", "HALLMARK_GLYCOLYSIS", "HALLMARK_DNA_REPAIR")
p1 <- plotGSEA(gse, plot_type = "volcano", show_pathway = 3, remove_legend = T)
p2 <- plotGSEA(gse, plot_type = "volcano", show_pathway = pathways)
p1 + p2 + plot_annotation(tag_levels = "A")
Volcano pathway plot of GSEA. default (A), select pathways (B).

Figure 12.2: Volcano pathway plot of GSEA. default (A), select pathways (B).

12.4 Multi-pathway Plot

If users want to show a bunch of selected pathways, plotGSEA borrows some code from fgsea.

By default, the top N pathways are shown. If users want to show a specific pathway, also pass the argument to show_pathway.

library(patchwork)
pathways <- c("HALLMARK_P53_PATHWAY", "HALLMARK_GLYCOLYSIS", "HALLMARK_DNA_REPAIR")
p1 <- plotGSEA(gse, plot_type = "fgsea", show_pathway = 5)
p2 <- plotGSEA(gse, plot_type = "fgsea", show_pathway = pathways)
p1 + p2 + plot_annotation(tag_levels = "A")
Multi-pathway plot of GSEA. default (A), select pathways (B).

Figure 12.3: Multi-pathway plot of GSEA. default (A), select pathways (B).

12.5 Ridge Plot

The ridge plot visualizes enriched pathways of up/down-regulated genes. The x-axis is fold change and the y-axis is pathways. Color represents the statistical value (e.g. pvalue/p.adjust/qvalue).

plotGSEA(gse,
  plot_type = "ridge",
  show_pathway = 10, stats_metric = "p.adjust"
)
Ridge plot of GSEA.

Figure 12.4: Ridge plot of GSEA.

12.6 Two-side Barplot

The barplot separates positive and negative NES into two sides. Users can specify the color for the two sides. Meanwhile, non-significant pathways (e.g. P-value > 0.05) will be colored “grey”.

plotGSEA(gse, plot_type = "bar", colour = c("navyblue", "orange"))
Two-side bar plot of GSEA.

Figure 12.5: Two-side bar plot of GSEA.

12.7 Borrow from plotEnrich

More plotting details are available at chapter 11

Take the geneheat plot as an example:

plotEnrich(gse$gsea_df, 
           plot_type = "geneheat", 
           show_gene = c("BRCA2", "CDK1", "MCM8", "TIPIN","FBL","ABCC2"), 
           fold_change = geneList)

12.8 Tricks

12.8.1 Change figure labels

If we want to DIY labels (e.g. make them lowercase for the plot above), we need to figure out which column the labels come from.

In the above geneheat plot, the labels come from the Description column, so we only need to change that column.

gse2 <- gse
gse2$gsea_df$Description <- tolower(gse2$gsea_df$Description)
# plotEnrich will automatically uppercase the first letter.
plotEnrich(gse2$gsea_df, 
           plot_type = "geneheat", 
           show_gene = c("BRCA2", "CDK1", "MCM8", "TIPIN","FBL","ABCC2"), 
           fold_change = geneList)