Closed
Description
Hi,
adding an annotation works only if global aesthetics have been defined in ggplot()
.
If there are only "local" aesthetics in individual geoms the annotation will not be drawn (no warning though).
library(ggplot2)
library(grid)
df <- data.frame(x = 1:10, y= 1:10)
anno <- annotation_custom(grid.rect(draw=FALSE), xmin = 7, xmax = 10,ymin = 1, ymax = 2)
## Global aesthetics: works fine
ggplot(df, aes(x = x, y = y)) + geom_point()+
anno
## "Local" aesthetics: does not work
ggplot() + geom_point(data = df, aes(x = x, y = y))+
anno
I tried setting scales
and/or coord
limits explicitly, but this doesn't make it work either:
ggplot() + geom_point(data = df, aes(x = x, y = y))+
anno +
scale_x_continuous(limits = c(-10,10)) +
scale_y_continuous(limits = c(-10,10)) +
coord_equal(xlim = c(-20,20), ylim = c(-20,20))