Arrange multiple (32) .png files in a grid
I was pulling my hair out last week trying to figure out rudimentary R coding, but it seems to be going nowhere (haven't used R since 2013, not that it's a great excuse).
All I want is a 4x8 grid composed of 32 .png files (maps I made) and I want to do this without loading one image file at a time ( http://www.statmethods.net/advgraphs/layout .html ).
So I can upload images in a folder (please correct me if my beliefs are bs)
img <- list.files(path='c:/a',patt='compo[0-32].*',full.names=T)
Then I thought, maybe, in the lines par(mfrow=c())
, layout
, grid.arrange
( record png-charts in the PDF file in the R ), grid.raster
( How to effectively combine multiple rgl graphs in one plot? ), That I have read and experimented, respectively, without leading to something standing.
The last one I only used with the following result
It made me giggle. I really don't think that lattice
is the way to go anyway.
Any help would be greatly appreciated!
source to share
Not sure if you care about loading all the image files - how else could you read your data to create a new image?
ETA: For uploading files, I just use png::readPNG
. One way to collect images is (12 images selected here)
filenames<-dir(pattern='compo')
foo<-list()
for(j in 1:12) foo[[j]]<-readPNG(filenames[j]
If you want to download them and use the basic tools plot
, then layout
this is the command you want. For example, for uploaded 12 images
layout(matrix(1:12,nr=4,byr=T))
for (j in 1:12) plot(foo[[j]])
source to share