Home > Software design >  How to save 2 separate ggplots overlapping in the same pdf in R?
How to save 2 separate ggplots overlapping in the same pdf in R?

Time:02-25

I have 2 ggplots: plot1 and plot2

When I show them in R using:

multi.page <- ggarrange(plot1, plot2,
                        nrow = 1, ncol = 1) 

I get the overlap, but when I then want to safe this overlapping images as PDF it is not possible:

ggsave('/path/image.pdf',plot=multi.page,width=8,height=5)

Does anyone know a way?

Maybe with ggplot_add?

Thank you!

CodePudding user response:

Instead of using ggsave, you could use the pdf device directly:

pdf('/path/image.pdf')
print(multi.page)
dev.off()

And you will have a pdf with your two plots on separate pages.

  • Related