How can I plot a "raster" object behind a shapefile object? Both plot fine on their own but the points don't plot over the raster:
require(rgdal)
require(maptools)
require(raster)
myproj = "+proj=utm +zone=12 +north +ellps=WGS84 +units=m"
shp = readShapeSpatial(fn.shp, proj4string = CRS(myproj))
ras = raster(fn.tif)
plot(ras)
plot(shp, bg="transparent", add=TRUE)
Overplotting raster plots with points, lines, and polygons should work just fine, as the following example shows.
My best guess would be that the
Spatial*
objects you are attempting to plot on top of the raster fall outside of the region being plotted. Have you checked that both theraster
andSpatial*
objects are in the same CRS, and (assuming they are) that the bounding boxes overlap? (i.e. trybbox(shp)
andbbox(ras)
, and compare the results).