I am using rasterVis::gplot() to plot a raster layer created by the rasterpackage. Plotting the raster alone works fine:
library(raster)
library(rasterVis)
r1 <- raster(nrow=10, ncol=10)
values(r1) <- runif(ncell(r1))
gplot(r1) +
geom_raster(aes(fill=value))
But when I try to add a rectangle on the plot usng geom_rect(), I get an error
df <- data.frame(xmin=-50, xmax=50, ymin=-50, ymax=50)
gplot(r1) +
geom_raster(aes(fill=value)) +
geom_rect(data=df, aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax))
Error in eval(expr, envir, enclos) : object 'y' not found
What am I doing wrong?

inherit.aes = FALSEto the geom_rect - Richard Telford