R 绘图可在一个pdf页面上多次绘图,而不是创建多个页面

R 绘图可在一个pdf页面上多次绘图,而不是创建多个页面,r,plot,R,Plot,我正在使用fgsea库为我的实验室分析一些数据,现在我正在使用plotGseaTable函数来绘制gsea表。基本功能工作正常: library(fgsea) data(examplePathways) data(exampleRanks) fgseaRes <- fgsea(examplePathways, exampleRanks, nperm=1000, minSize=15, maxSize=100) topPathways <- fgseaRes[head(order(

我正在使用
fgsea
库为我的实验室分析一些数据,现在我正在使用
plotGseaTable
函数来绘制gsea表。基本功能工作正常:

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()


这是函数的问题吗?有什么方法可以告诉
pdf()
函数开始新页面吗?

您可以使用
plot.new()
命令强制pdf中的分页符

e、 g


path不会改变我这边的任何东西。如果在每行之间不使用
par()
而使用plot,它仍然会创建多个页面。@Whitehot True,但设置
mfrow
会引入分页符(cf)。可以在
par()
调用之后添加
plot.new()
命令?
plot.new()
工作,无论是否使用
par(…)
。非常感谢。
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()
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()