This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Add NES value to GSEA plot

I am using the gseaplot2 function from enrichplot to mimic the GSEA figure that comes from the software. I would like to add the NES value to the plot, and tried editing the function but results in a error. GSEA

The function used is

  gseaplot2(GSEAobject, geneSetID = 1, title = GSEAobject$Description[1],pvalue_table = TRUE)

I tried editing the gseaplot2 function to include the NES value in the pvalue_table part of the function but the error I get is

Error in x$children[[i]] : no such index at level 1

Source of the function at gseaplot2

r enrichplot clusterprofiler gsea

1 answer

Hi I have the same concern and then made a solution:

trace("gseaplot2", edit = TRUE)

In the function, look for "if (pvalue_table) {..." and modify the code from:

if (pvalue_table) {
pd <- x[geneSetID, c("Description", "pvalue", "p.adjust")]
rownames(pd) <- pd$Description
pd <- pd[, -1]

to

if (pvalue_table) {
pd <- x[geneSetID, c("NES", "pvalue", "p.adjust")]
rownames(pd) <- ""
pd <- pd[, ]

Hope it helps!

For those who want to apply this change permanently (i.e will apply when knitting the document), I made a fork with the code change.

remove.packages("enrichplot")
invisible(lapply(paste0('package:', names(sessionInfo()$otherPkgs)), detach, character.only=TRUE, unload=TRUE)) # unload all packages
devtools::install_github("BarryDigby/enrichplot")

Thanks @lianchee11 for the code.

* The pathway description in green font will be omitted from the plot.

Log in to answer this question.