1

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

lanselibai
  • 1,203
  • 2
  • 19
  • 35
  • 1
    Search for `mfrow` and you will find many examples. – lmo May 13 '18 at 11:48
  • but all the example I can see is to go through the plotting procedure, but I want to skip that. I just want the combining step. – lanselibai May 13 '18 at 11:51
  • Take a look at [this post](https://stackoverflow.com/questions/12918367/how-to-plot-with-a-png-as-background). It might get you what you are looking for together with my suggestion above. – lmo May 13 '18 at 11:55
  • could you please write an example for me? – lanselibai May 13 '18 at 11:57

1 Answers1

2

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)
jspcal
  • 50,847
  • 7
  • 72
  • 76