Skip to content

Support for using I() to use NPC corodinates seems incomplete #5656

@aphalo

Description

@aphalo

@teunbrand I could not find an open issue on this, but I remember seeing a rather recent commit by you implementing this new feature. In 3.4.4.9000 I see it working in annotate() and in aes() but not with values mapped to constants in calls to geoms (at least geom_label()). By the way, it is great to see this implemented in 'ggplot2'. It makes several geometries in 'ggpp' redundant which is, I think, an indication of usefulness, as now all geometries become usable with NPC coordinates.

library(ggplot2)

ggplot(data = mtcars,
       mapping = aes(x = disp, y = mpg, colour = factor(cyl))) +
  geom_point() +
  annotate(geom = "label", x = I(0.5), y = I(0.9), label = "a label")

ggplot() +
  geom_point(mapping = aes(x = disp, y = mpg, colour = factor(cyl)),
             data = mtcars) +
  geom_label(mapping = aes(x = I(x), y = I(y), label = label),
             data = data.frame(x = 0.5, y = 0.9, label = "a label"))

ggplot(data = mtcars,
       mapping = aes(x = disp, y = mpg, colour = factor(cyl))) +
  geom_point() +
  geom_label(x = I(0.5), y = I(0.9), label = "a label", colour = "black")

ggplot(data = mtcars,
       mapping = aes(x = disp, y = mpg, colour = factor(cyl))) +
  geom_point() +
  geom_label(x = 300, y = 32, label = "a label", colour = "black")

Created on 2024-01-22 with reprex v2.1.0

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