将 .png 文件读入 R 并创建多重绘图

A K*_*K R 1 r

我有兴趣使用以下命令从我的计算机读取 png 文件并从中生成多个文件。

plot(0:2, 0:2, type = "n", xaxt = "n", yaxt = "n", xlab = "", ylab =      "")
rasterImage(readPNG(source="ArgentinaTotal.png"), 0, 1, 1, 2)
rasterImage(readPNG(source="BrazilTotal.png"), 1, 1, 2, 2)
rasterImage(readPNG(source="ChileTotal.png"), 0, 0, 1, 1)
rasterImage(readPNG(source="ColombiaTotal.png"), 1, 0, 2, 1)
Run Code Online (Sandbox Code Playgroud)

这些命令适用于 2X2 设置,但如果我想要 2 列和 4 行的倍数,我该怎么办?我使用了以下代码:

plot(0:2, 0:4, type = "n", xaxt = "n", yaxt = "n", xlab = "", ylab = "")
Run Code Online (Sandbox Code Playgroud)

但我收到一条错误消息:

Error in xy.coords(x, y, xlabel, ylabel, log) : 
   'x' and 'y' lengths differ
Run Code Online (Sandbox Code Playgroud)

Ist*_*rel 5

您所需要的只是在通话中正确指定xlim和。例如:ylimplot

img <- readPNG(system.file("img", "Rlogo.png", package="png"))

plot(NA, xlim = c(0, 2), ylim = c(0, 4), type = "n", xaxt = "n", yaxt = "n", xlab = "", ylab = "")
rasterImage(img, 1, 3, 2, 4)
rasterImage(img, 1, 2, 2, 3)
rasterImage(img, 1, 1, 2, 2)
rasterImage(img, 1, 0, 2, 1)
Run Code Online (Sandbox Code Playgroud)

这是一个示例输出: 示例输出