79382128

Date: 2025-01-23 18:09:12
Score: 0.5
Natty:
Report link

I was also interested in this so I looked into it and I think I have might found an elegant solution. enrichplot::gseaplot2 generates enrichment plots consisting of 3 gg elements. If you store your gseaplot2, each plot can then be modified to add the group labels, enrichment score, qvalue and so on. As an example: First generate the full plot

test <- enrichplot::gseaplot2(GSEA_Hallmarks,

color = "#0d76ff",

# first gene set on the list of Hallmarks results generated with the GSEA function
geneSetID = GSEA_Hallmarks@result[[1, 1]],

#title on plot. Modify it so the remove the underscores and limit the length
title = paste0("Enrichment plot \n", str_wrap(str_replace_all(as.character(GSEA_Hallmarks@result[[1, 1]]), "_", " "), width = 35)),)

Then, modify the lower plot to add the groups below the middle plot. The positions of the labels will depend on each GSEA:

test[[3]] <- test[[3]] + annotate("text", x = c(100, 5900), y = c(10, 10), label = c("Resistant", "Parental"), hjust = c(0, 1))

Then the top plot to add the NES and qvalue. Again, the positions of the labels will depend on each GSEA:

test[[1]] <- test[[1]] + annotate("text", x = 4500, y = -0.05, label = paste("NES:",
                                                                       round(GSEA_Hallmarks@result$NES[1], digits = 2),
                                                                     "\nqvalue:",
                                                                     formatC(GSEA_Hallmarks_GSE165914@result$qvalue[1], format = "e", digits = 3)),
                              hjust = 0)

And finally print it:

test

It should look like this: enrichment plot

All this could be put into a function (or a loop) so one don't have to type all this for each plot. I've just found this way and wanted to share it. Finally, it's my first contribution to SO, so I hope I've done it correctly :) Cheers, Mariano

Reasons:
  • Blacklisted phrase (1): Cheers
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Mariano Zacarías-Fluck