In the documentation, there's one example showing the usage of annotation_raster
as below.
ggplot(aes(x=mpg, y=wt), data=mtcars) +
annotation_raster('red', -Inf, Inf, -Inf, Inf) +
geom_point()
This works fine, however, when I move the data and aes into the layer, suddenly it doesn't work anymore:
ggplot() +
annotation_raster('red', -Inf, Inf, -Inf, Inf) +
geom_point(aes(x=mpg, y=wt), data=mtcars) # doesn't work
This is perplexing because to me these two seem semantically identical.
Is there a reason why the second line won't work and is there a way to use annotation_raster
without specifying data and aes early in the base layer?