Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R-使用光栅图像为图像添加标题_R_Raster_R Grid - Fatal编程技术网

R-使用光栅图像为图像添加标题

R-使用光栅图像为图像添加标题,r,raster,r-grid,R,Raster,R Grid,我有12个PNG文件,我想结合在一个单独的绘图与4x3网格在R 到目前为止,我可以用 plot(c(0,4), c(0,3), type = "n", xaxt = "n", yaxt = "n", xlab = "", ylab = "") 我可以用 rasterImage(readPNG("image1.png"), 0, 3, 1, 2) rasterImage(readPNG("image2.png"), 1, 3, 2, 2) 等等 我得到了我想要的,但我还想为情节中的每个图像添加

我有12个PNG文件,我想结合在一个单独的绘图与4x3网格在R

到目前为止,我可以用

plot(c(0,4), c(0,3), type = "n", xaxt = "n", yaxt = "n", xlab = "", ylab = "")
我可以用

rasterImage(readPNG("image1.png"), 0, 3, 1, 2)
rasterImage(readPNG("image2.png"), 1, 3, 2, 2)
等等

我得到了我想要的,但我还想为情节中的每个图像添加一个标题。像image1应该有一个。图像1和图像2应具有b。图像2位于图像顶部。在R有什么办法吗

提前谢谢

试试这个:

 text(x=0.5,y=2.95, labels="a. Image1")
 text(x=1.5,y=2.95, labels="b. Image1")
如果需要加粗,则需要plotmath表达式:

text(x=1.5,y=2.95, labels=expression( bold(b.~Image1) )  )

BondedDust提出的使用文本的建议是完美的,但是使用PAR中的MFROW或MFCOL图形参数来布局情节网格可能是明智的。然后可以使用plot…、main='foo'或titlemain='foo'添加标题。例如:

下载一些png图形示例,并将其读入列表:

library(png)
pngs <- lapply(LETTERS[1:12], function(x) {
  u <- 'http://icons.iconarchive.com/icons/mattahan/umicons/64'
  download.file(mode='wb', sprintf('%s/Letter-%s-icon.png', u, x), 
                f <- tempfile(fileext='.png'))
  readPNG(f)
})

比我的好。我打算建议main=bquotebold.pasteLETTERS[I],”。“图像”,但后来我注意到您使用了font=2选项。@BondedDust我还没有熟悉bquote、表达式、plotmath等。出于某种原因,它影响了我的头脑!我看到了你的其他贡献。我毫不怀疑,随着时间的推移,它们将成为您的有用工具。我碰巧认为?plotmath页面写得很差。我注意了彼得·达尔加德和加博·格罗森戴克在Rhelp上的工作实例来学习它。@BondedDust-谢谢你的提示。我会花点时间的。
par(mfrow=c(4, 3), mar=c(0, 0, 3, 0))
sapply(seq_along(pngs), function(i) {
  plot.new()
  plot.window(xlim=c(0, 1), ylim=c(0, 1), asp=1)
  rasterImage(pngs[[i]], 0, 0, 1, 1)
  title(paste0(letters[i], '. Image ', i), font.main=2)
})