NicolasH2 / gggsea

GSEA plots in ggplot2
8 stars 4 forks source link

Drawing multiple enrichment plots on same graph #5

Open sg3451 opened 1 month ago

sg3451 commented 1 month ago

Wondering if there is a way to plot >1 enrichment plot on the same graph? A use-case is when the same pathway is being compared under two different conditions. If the enrichment plots for the pathway significantly differs between the two conditions, it will be great to visualize it in the same plot. Just a thought. I know the DOSE package has some way of doing this, but it would be great if gggsea can do this also.

NicolasH2 commented 2 weeks ago

Hi @sg3451 , thanks for reaching out. This is indeed possible with gggsea: 1) Use the gseaCurve function separately on each of your conditions. 2) Modify the outcome so that the condition name is part of the pathway name 3) Combine the data of both conditions and plot the result

# standard procedure, with your conditions being constructed separately
library(gggsea)
library(ggplot2)
setlist <- gggsea::mySetlist
rl1 <- gggsea::myRankedlist #use your condition 1
df1 <- gseaCurve(rl1, setlist)
rl2 <- gggsea::myRankedlist #use your condition 2
df2 <- gseaCurve(rl2, setlist)
#-------------------------------------
# modify the data, so that your condition appears in the pathway name
df1$set <- paste("condition1",df1$set)
df2$set <- paste("condition2",df2$set)
#------------------------------------
# combine and plot
df <- rbind(df1,df2)
ggplot2::ggplot() + 
  geom_gsea(rbind(df))