【问题标题】:Plotting multiple .TIFF images together with individual titles in R在 R 中绘制多个 .TIFF 图像以及单个标题
【发布时间】:2023-03-28 08:12:01
【问题描述】:

我想在 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()' 可能不适合这项工作(因为我没有绘制地图),但我想知道是否有办法让它工作?如果没有,有没有我可以使用的替代方案?提前谢谢你。

【问题讨论】:

    标签: r plot raster tiff


    【解决方案1】:

    我设法使用更合适的图像处理包找到了解决此问题的方法:

    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
    

    【讨论】:

      猜你喜欢
      • 2019-06-14
      • 1970-01-01
      • 2018-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多