Reputation: 85
I am interested in using the following commands to read png files from my computer and making a multiple from them.
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)
The commands work fine for a 2X2 setup but what should I do if I want to have multiple of 2 columns and 4 rows? I used the following code:
plot(0:2, 0:4, type = "n", xaxt = "n", yaxt = "n", xlab = "", ylab = "")
But I get an error message:
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
Upvotes: 1
Views: 9995
Reputation: 2588
All you need is to properly specify xlim
and ylim
in your plot
call.
For example:
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)
And here is an example output:
Upvotes: 5