lanselibai
lanselibai

Reputation: 1273

How to put multiple existing graphs in a same plot?

This links explains how to plot multiple graphs in a same overall plot.

Now I have three existing graphs, png1, png2, png3. I want a layout like below. How to achieve this?

enter image description here


Thank you very much for the answer, please remember to install the packages:

install.packages("png")
library(png)
install.packages("gridExtra")
library(gridExtra)

After using the gridExtra, I combined three graphs together. However, they had very low resolution. How can I make them at least the same resolution as the original ones?

enter image description here

Upvotes: 1

Views: 297

Answers (1)

jspcal
jspcal

Reputation: 51894

You would use the par or layout function. See the examples here: https://www.rdocumentation.org/packages/graphics/versions/3.5.0/topics/layout

If you're interested in inserting image files into the plot, you'd use readPNG and rasterImage and/or the grid raster functions.

Example:

png1 = png::readPNG("png1.png")
png2 = png::readPNG("png2.png")
png3 = png::readPNG("png3.png")
images = list(png1, png2, png3)
grobs = lapply(images, grid::rasterGrob)
gridExtra::grid.arrange(grobs=grobs)

Upvotes: 2

Related Questions