5

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?

xzhu
  • 5,675
  • 4
  • 32
  • 52
  • 5
    it could probably be called a bug, but note that you can provide any dummy data in the base layer, `ggplot(data.frame(x=1,y=1), aes(x=x, y=y))` will do just as well. It's probably the strategy of training / stretching the scales that requires a real-data layer in a first step. – baptiste Jul 14 '15 at 01:27
  • https://github.com/hadley/ggplot2/issues/1164 – Brian Diggs Jul 14 '15 at 18:09

0 Answers0