You can use the rasterImage
function to add a raster to an existing graph, it will then be the background for anything added on top of that. See the link in @mplourde's comment for ways to read jpeg or other image formats in that can then be used with rasterImage
.
Running par('usr')
will give you the current user coordinates to plot from axis to axis or you can use grconvertX
and grconvertY
to find other sets of coordinates. So for a histogram you could plot the histogram, then use rasterImage
to place your image, then use hist again with add=TRUE
:
tmp <- rnorm(100)
hist(tmp)
image <- as.raster(matrix(0:1, ncol=5, nrow=3))
tmp2 <- par('usr')
rasterImage(image, tmp2[1], tmp2[3], tmp2[2], tmp2[4])
hist(tmp, add=TRUE, border='red', lwd=3)
However, be very careful that the background image does not distract from the histogram itself, possibly fading your image or adding an alpha channel to make it semitransparent can help.