Skip to content

Class clash for annotation_custom default args #6675

@bbcuffer

Description

@bbcuffer

Hi, if my x-aesthetic is a date, annotate_custom generates conversion warnings when I use the defaults for xmin and xmax (which are numeric: -Inf).

ggplot(economics, aes(x = date, y = unemploy)) + 
  geom_line() + 
  annotation_custom(grid::textGrob("DRAFT"))

yields

Warning messages:
1: In scale_x_date() :
  A <numeric> value was passed to a Date scale.
ℹ The value was converted to a <Date> object.
2: In scale_x_date() :
  A <numeric> value was passed to a Date scale.
ℹ The value was converted to a <Date> object.

And a perfectly good plot.

The workaround for the warnings is to specify that xmin and xmax are dates explicitly. e.g.

ggplot(economics, aes(x = date, y = unemploy)) + 
  geom_line() + 
  annotation_custom(grid::textGrob("DRAFT"), xmin = as.Date(-Inf), xmax = as.Date(Inf))

Would it be possible to have the defaults match the class of these arguments to to the class of the x aesthetic?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions