我感兴趣的是使用以下命令从我的计算机中读取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)
这些命令适用于2X2设置,但如果我想拥有2列和4行的多个,我该怎么办? 我使用了以下代码:
plot(0:2, 0:4, type = "n", xaxt = "n", yaxt = "n", xlab = "", ylab = "")
但是我收到一条错误消息: xy.coords(x,y,xlabel,ylabel,log)中的错误: 'x'和'y'长度不同
答案 0 :(得分:2)
您只需在xlim
来电中正确指定ylim
和plot
即可。
例如:
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)