Skip to content

Annotations work only if global aes() have been defined #1655

Closed
@bleutner

Description

@bleutner

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 

selection_065

selection_066

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))

Metadata

Metadata

Assignees

Labels

bugan unexpected problem or unintended behavior

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions