r – How to plot 2 jpegs side by side in same output?

I want to plot 2 jpegs images side by side within the same output.

I have tried to do this two different ways as follows:

library(jpeg)

jpeg("map1.jpeg")
# Set for 2 rows, 1 col
map1 <- par(mmfrow=c(1,2),mar=c(9,4,1,0))

jpeg("map2.jpeg")
map2 <-par(mfrow=c(1,2),mar=c(9,4,1,0))

#plot
par(map1, map2)
# Close the device
dev.off()

However, when I attempt this, I only receive this output:

Show in New Window
[[1]]
NULL

[[2]]
NULL

jpeg
2

I have also tried reading the jpegs as rasters.

par(mfrow=c(1,2))
map1 <- raster("map1.jpeg")
map2 <- raster("map2.jpeg")
plot(map1)
plot(map2)

This one shows yellow squares instead of the images…

Does anyone know how to fix this? Thank you.

Read more here: Source link