library(ggplot2) library(gridExtra) library(cowplot) # Sample data for plot1 data1 <- data.frame(x = 1:10, y = 1:10) # Sample data for plot2 data2 <- data.frame(x = 1:10, y = 10:1) # Create ggplot objects plot1 <- ggplot(data1, aes(x, y)) + geom_line() plot2 <- ggplot(data2, aes(x, y)) + geom_line() # Open a PDF device to save the plots pdf("arranged_plots.pdf", width = 10, height = 5) # Arrange and print the plots using gridExtra grid.arrange(plot1, plot2, nrow = 2) # Or arrange and print the plots using cowplot # plot_grid(plot1, plot2, nrow = 1) # Close the PDF device to save the plots to the PDF file dev.off()