Whitehot
Whitehot

Reputation: 497

plotGseaTable plotting multiple times on one pdf page instead of creating mutliple pages

I am using the fgsea library to analyse some data for my lab, and right now I'm using the plotGseaTable function to, well, plot gsea tables. The basic function works fine:

library(fgsea)

data(examplePathways)
data(exampleRanks)

fgseaRes <- fgsea(examplePathways, exampleRanks, nperm=1000, minSize=15, maxSize=100)
topPathways <- fgseaRes[head(order(pval), n=15)][order(NES), pathway]

pdf(paste0(outdir, "testgseatable.pdf"))

plotGseaTable(examplePathways[topPathways], exampleRanks, fgseaRes, gseaParam=0.5)

dev.off()

basic plotGseaTable plot

However, once I try and look at multiple rankings and plot those, it prints all of the diagrams on a single page:

myranks_1 = rnorm(length(exampleRanks), 50, 7)
names(myranks_1) = names(exampleRanks)
myres_1 = fgsea(examplePathways, myranks_1, nperm=1000, minSize=15, maxSize=100)
mytop_1 = myres_1[head(order(pval), n=15)][order(NES), pathway]

myranks_2 = rnorm(length(exampleRanks), 50, 7)
names(myranks_2) = names(exampleRanks)
myres_2 = fgsea(examplePathways, myranks_2, nperm=1000, minSize=15, maxSize=100)
mytop_2 = myres_2[head(order(pval), n=15)][order(NES), pathway]
myranks_3 = rnorm(length(exampleRanks), 50, 7)
names(myranks_3) = names(exampleRanks)
myres_3 = fgsea(examplePathways, myranks_3, nperm=1000, minSize=15, maxSize=100)
mytop_3 = myres_3[head(order(pval), n=15)][order(NES), pathway]
myranks_4 = rnorm(length(exampleRanks), 50, 7)
names(myranks_4) = names(exampleRanks)
myres_4 = fgsea(examplePathways, myranks_4, nperm=1000, minSize=15, maxSize=100)
mytop_4 = myres_4[head(order(pval), n=15)][order(NES), pathway]
myranks_5 = rnorm(length(exampleRanks), 50, 7)
names(myranks_5) = names(exampleRanks)
myres_5 = fgsea(examplePathways, myranks_5, nperm=1000, minSize=15, maxSize=100)
mytop_5 = myres_5[head(order(pval), n=15)][order(NES), pathway]


pdf(paste0(outdir, "testgseatable_multiple.pdf"))

plotGseaTable(examplePathways[mytop_1], myranks_1, myres_1, gseaParam=0.5)
plotGseaTable(examplePathways[mytop_2], myranks_2, myres_2, gseaParam=0.5)
plotGseaTable(examplePathways[mytop_3], myranks_3, myres_3, gseaParam=0.5)
plotGseaTable(examplePathways[mytop_4], myranks_4, myres_4, gseaParam=0.5)
plotGseaTable(examplePathways[mytop_5], myranks_5, myres_5, gseaParam=0.5)

dev.off()

unholy child of nightmares, multiple text plots on a single page, characters overlapping

Is this a problem with the function? Is there some way to tell the pdf() function to start a new page?

Upvotes: 0

Views: 662

Answers (2)

Miguel Prieto
Miguel Prieto

Reputation: 93

I found a workaround using ggplot

I just added

ggplot() + theme_void()

before running

plotGseaTable()

Upvotes: 1

RoB
RoB

Reputation: 1984

You can use the plot.new() command to force a page break in the pdf.

e.g

path <- "~/Desktop/tests/"
pdf(file = paste0(path, "myplot.pdf"))
par(mfrow = c(1,2))

plot(rnorm(10), main = 1)

plot.new()

plot(rnorm(10), main = 2)
plot(rnorm(10), main = 3)

dev.off()

AA

Upvotes: 1

Related Questions