# create a small greyscale matrix, and write it to a PNG file
ras <- matrix(c('#880000', '#000088'), 3, 4)
ras <- grDevices::as.raster(ras)
pngfile <- tempfile()
write_png(ras, file = pngfile)
ras2 <- read_png(pngfile, type = 'raster')
plot(ras2, interpolate = FALSE)
Run the code above in your browser using DataLab