在网格中排列多个(32).png文件 [英] Arrange multiple (32) .png files in a grid

查看:57
本文介绍了在网格中排列多个(32).png文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去一周,我一直在努力寻找基本的R编码,但似乎一无所获(自2013年以来就没有使用过R,这并不是一个很好的借口).

I've been pulling my hair out for the past week trying to figure out elementary R coding but can't seem to get anywhere (haven't used R since 2013 not that its a great excuse).

我想要的是一个由32个.png文件组成的 4x8网格(我制作的地图),我想做到这一点而不必一次加载一个图像文件( http://www.statmethods.net/advgraphs/layout.html ).

All I want is a 4x8 grid made up of 32 .png files (maps I've made), and I want to do it without loading one image file at a time (http://www.statmethods.net/advgraphs/layout.html).

所以我想我可以将图像加载到文件夹中(如果我的想法是bs,请更正我的想法)

So I think I can load the images within the folder writing (please correct me if my beliefs are bs)

img <- list.files(path='c:/a',patt='compo[0-32].*',full.names=T)

然后我在想也许是在 par(mfrow = c()) layout grid.arrange (将png图写入R中的pdf文件), grid.raster (如何将多个rgl图有效地合并为一个图?)-我已经阅读并尝试过该方法,因此没有任何值得的结果.

Then I was thinking maybe in the lines of par(mfrow=c()), layout, grid.arrange (writing png plots into a pdf file in R), grid.raster (How to join efficiently multiple rgl plots into one single plot?) - which I've read up on and experimented with accordingly not resulting in anything worthwhile..

我仅使用了以下结果的

The latter I employed only with the following outcome

这使我咯咯笑.我真的不认为 lattice 是要走的路.

It made me giggle. I don't really think lattice is the way to go anyway.

任何帮助将不胜感激!

推荐答案

另一种方法是使用readPNG读取PNG图像,然后使用grid和gridExtra:

Another approach is to read the PNG images with readPNG then use grid and gridExtra:

library(png)
library(grid)
library(gridExtra)

plot1 <- readPNG('plot1.png')
plot2 <- readPNG('plot2.png')

grid.arrange(rasterGrob(plot1),rasterGrob(plot2),ncol=1)

这篇关于在网格中排列多个(32).png文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆