Building multiple JPEG images on one display

I need to display and display several jpeg images on one combined display (or canvas?). For example, suppose I have images of {a, b, c, d} .jpg, each of different sizes, and I would like to build them on one page in a 2x2 grid. It would also be nice to be able to set a title for each subtitle.

I carefully searched for a solution, but could not find out how to do it, so any ideas really help. I would prefer to use a solution based on the EBImage package.

+7
r image plot
source share
3 answers

There are two ways to organize several graphs with the functions of the base graph, namely par(mfrow=c(rows,columns)) (replace rows and columns with integers) and layout(mat) , where mat is a matrix of type matrix(c(1,2,3,4)) . <w> For more information, see ?par ?layout , and especially Quick-R: combining charts .

However, since your question is about images, I don't know if this helps you at all. If not, I regret the misinterpretation of your question.

+4
source share

To add to Henriks's solution, a rather convenient way to use the par () function is:

 jpeg(filename="somefile.jpg") op <- par(mfrow=c(2,2) #plot the plots you want par(op) dev.off() 

Thus, you return the parameters back to the old state after running the code. Remember that this is NOT true if one of the sites gave an error.

Remember that R always places the graphs in the same order. Using mfrow fills the grid in a row row by row. If you use mfcol instead of mfrow in your code, you populate the column column by column.

The layout is a completely different story. Here you can determine in which order the plots should be placed. So layout(matrix(1:4,nrow=2) does the same thing as par(mfcol=c(2,2)) . But layout(matrix(c(1,4,3,2),ncol=2)) places the first left chart, the next right one, the third one to the right, and the last left tray.

Each plot is completely independent, so the headers that you specify with the main option are printed. If you want more flexibility, you should take a look at the grid graphics.

+2
source share

If you do not want the images in a regular grid (different sizes could imply this), you can use the subtask function from the TeachingDemos package. In the last example, the help page shows the use of the image as a build symbol, just change it to use different images and sizes / locations.

The ms.image function (same package) used with my.symbols is another option.

+1
source share

All Articles