This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to manually sort the legend of gseaplot2 (enrichplot, clusterProfiler) result?

Hello everyone,

I am trying to plot GSEA results using the gseaplot2 function. I want to plot the top5 highest and lowest NES results. The plotting itself works, however the legend is not in the same order as my results, but ordered alphabetically. I would like the legend to be in the same order as the lower part of the plot. Is there a way to automatically or manually do this? For instance by passing a vector with the labels in the right order to the plot object.

gseaplot2(GSEAresults,geneSetID = rev(c(1:5,(length(GSEAresults$Description)-4):(length(GSEAresults$Description))))
      ,pvalue_table = FALSE,subplots = 1:2)

exampleplot

gseaplot2 enrichplot ggplot2 clusterprofiler

ggplot2 automatically order alphabetically, to change that you need to reorder the levels of the element you are plotting. GSEAresults$Description in your case. GSEAresults$Description <- factor(GSEAresults$Description, levels = c("here you rnew order")

0 answers

No answers yet.

Log in to answer this question.