Hi,
I have been using the package fgsea, and I would like to use a for loop in R to output multiple Enrichment plots.
So far I can generate a plot of the desired pathway using:
plotEnrichment(pathway =
pathways.hallmark[["HALLMARK_EPITHELIAL_MESENCHYMAL_TRANSITION"]],
gseaParam = 1, ticksSize = 0.5, stats= ranks)
+ labs(title="Epithelial to Mesenchymal Transition")
+ theme(plot.title = element_text(hjust = 0.5, face="bold"))
I decided to capture the statistically relevant pathways, and attempted to use a for loop to output them all at once:
filtered_pathway <- subset(fgseaResTidy, pval < 0.05)
filt_p <- as.vector(filtered_pathway$pathway)
filt_p
[1] "HALLMARK_APICAL_JUNCTION" "HALLMARK_MYOGENESIS"
[3] "HALLMARK_HEDGEHOG_SIGNALING" "HALLMARK_PI3K_AKT_MTOR_SIGNALING"
...
for (i in filt_p){
plotEnrichment(pathway = pathways.hallmark[[i]],
gseaParam = 1, ticksSize = 0.5, stats= ranks) +
labs(title=i) + theme(plot.title = element_text(hjust = 0.5, face="bold"))
}
This code does not generate anything. I am aware this is not a bioinformatics question, however I have no doubt many would be able to point out the problem in 2 seconds. Hopefully this post will be helpful to people using fgsea in the future.
Kind regards,
Barry
I'd think that this code is writing to the same device in such quick succession that you don't get to see the output, or maybe the last time the loop is executed, a blank plot is generated. Are you using RStudio?
Hi Ram,
Yes I am using R studio. To test that theory I placed
To try and capture all plots in 1 pdf. The resulting pdf cannot be opened (is damaged).