我使用 for 循环创建了许多图ggplot
,并将每个图保存到一个列表中plots
。
plots <- list()
for (i in 1:238)
{
gene <- row.names(geneExpression)[i]
df.sub <- df[ , c("source", gene)]
names(test.sub) <- c("source", "exp")
plots[[i]] <- ggplot() + geom_violin(data=test.sub, aes(source, exp, fill=source, color=source), alpha=.4, trim=F, environment = environment()) + coord_flip() + ggtitle(gene) + theme(legend.position="none") + labs(x="")
}
我正在使用其他地方建议的 gridExtra 函数,但是当我这样做时,它会在一个页面中打印所有图(240 个图)。
pdf("violinPlots.pdf")
do.call(grid.arrange, plots)
dev.off()
有没有办法可以指定我想要每页 24 个图?(即 6 行 x 4 列?)
我试过这个,但它返回一个错误......
grid.arrange(plots, ncol=4, newpage = T )