我想在R中绘制多个.TIFF图像,并为它们添加单独的标题。在没有标题的情况下,这段代码可以完成工作:
require(raster)
setwd("...")
files = list.files(pattern="*.tif")
tiff("balanded_1.tiff", units="in", width=21, height=26, res=300, compression = 'lzw') #for saving
par(mfrow=c(5,3))
for (i in 1:15) {
plotRGB(brick(files[i]))
}
dev.off() #save figure
但是,如果我尝试使用'plotRGB()‘向图片添加单独的标题,它会自动为它们添加轴(因为'axes=TRUE’成为'plotRGB()' function中的一个要求),我得到的结果如下所示:
plotRGB(brick(files[2]), axes=TRUE, main="TITLE", xlab="", ylab="")
我知道'plotRGB()‘函数可能不适合这项工作(因为我不是在绘制地图),但我想知道是否有方法可以让它工作?如果没有,有没有其他方法可以让我使用?提前谢谢你。
发布于 2020-07-17 07:47:09
我设法找到了这个问题的解决方案,使用了一个更合适的图像处理包:
require(magick)
setwd("...")
files = list.files(pattern="*.tif")
tiff("balanded_1.tiff", units="in", width=21, height=26, res=300, compression = 'lzw')
par(mfrow=c(5,3))
for (i in 1:15) {
name <- files[i]
lag <- strsplit(name, "_")[[1]][2] #get the name right for the image
match <- strsplit(name, "_")[[1]][4]
lead <- strsplit(name, "_")[[1]][6]
lead <- strsplit(lead, ".tiff")[[1]][1]
name <- paste(" Lag=",lag,", Match=1:",match,", Lead=",lead, sep = "") #put the name together
img <- image_annotate(image_read(files[i]), name, font = 'Times', size = 120) #read the image and add the name
img <- image_crop(img, "1500x1050")
plot(img)
}
dev.off() #save figure
https://stackoverflow.com/questions/62807302
复制相似问题