Skip to content

Broken support on annotation_custom() #6716

@yotasama

Description

@yotasama

I found a problem with ggplot2 4.0.0 which generate broken result when using transformed coord with annotation_custom(grob)
Here is the code to reproduce the bug:

library(ggplot2)
library(grid)
df <- data.frame(x = 1:10, y = 1:10)
ggplot(df, aes(x = x, y = y)) +
  geom_point() +
  scale_y_continuous("y", expand = c(0.1, 0.1), transform = "log10") +
  annotation_custom(
    grob = grid::textGrob("some text",
                          x = unit(0.5, "npc"),
                          y = unit(0.9, "npc"),
                          gp = grid::gpar(fontsize = 12)
    )
  )

The behavior in 3.5.0 was expected:
Image

But I got this in 4.0.0:
Image
with warning:
In log(x, base) : NaNs produced

I guess the problem was that the transform was wrongly applied to the grob.

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