There are two problems with this question. One of them is how to get ggplot2 to draw a Raster * object. Another way is to reprogram the raster by storing its values.
OP contains code
library(dismo) e = extent(-14 , 58 , 28 , 64) mapImageData2 <- gmap(e, type = c("terrain"), lonlat = TRUE, path = "&style=feature:all|element:labels|visibility:off&style=feature:administrative.country|element:geometry.stroke|visibility:off")
If we run this and then do plot(mapImageData2) , we get a good plot. Then OP starts
mapImageData2_proj <- projectExtent(mapImageData2, crs = "+proj=utm +zone=31 +datum=WGS84")
Now, if we run plot(mapImageData2_proj) , we get an error! This is because projectExtent returns a RasterLayer with no values. Instead, we should use projectRaster() . See ?projectExtent more details. So we run:
mapImageData2_proj <- projectRaster(mapImageData2, crs = "+proj=utm +zone=31 +datum=WGS84") plot(mapImageData2_proj)
Now we see the redesigned display. Progress! But we still cannot build mapImageData2_proj with ggplot2 , because ggplot2 does not know how to handle the Raster * object. We need to convert our raster file to a data frame. There are several ways to do this, but without downloading any additional packages, raster::rasterToPoints() is a good option. For example:
myPoints <- raster::rasterToPoints(myRaster) myDataFrame <- data.frame(myPoints) colnames(myDataFrame) <- c("Longitude", "Latitude", "Values") ggplot(data=myDataFrame, aes_string(y = "Latitude", x = "Longitude")) + geom_raster(aes(fill = Values))
So, to put it all together in the OP example:
library(dismo) e = extent(-14 , 58 , 28 , 64) mapImageData2 <- gmap(e, type = c("terrain"), lonlat = TRUE, path = "&style=feature:all|element:labels|visibility:off&style=feature:administrative.country|element:geometry.stroke|visibility:off") plot(mapImageData2) mapImageData2_proj <- projectRaster(mapImageData2, crs = "+proj=utm +zone=31 +datum=WGS84") plot(mapImageData2_proj) myRaster <- mapImageData2_proj myPoints <- raster::rasterToPoints(myRaster) myDataFrame <- data.frame(myPoints) colnames(myDataFrame) <- c("X", "Y", "Values") ggplot(data=myDataFrame, aes_string(y = "Y", x = "X")) + geom_raster(aes(fill = Values))