Skip to content

Conversation

@mjskay
Copy link
Contributor

@mjskay mjskay commented Dec 22, 2023

This PR is a proof-of-concept for support of unit() throughout ggplot2. It shows how some of the ideas in #5609 might be implemented.

To tease, it would allow you to do stuff like this:

data.frame(var1 = 1:5, var2 = 1:5, name = letters[1:5]) |>
  ggplot(aes(var1, var2)) + 
  geom_point() +
  geom_line() +
  # labels exactly 10 points right of their points, no matter how the
  # plot is resized
  geom_text(aes(label = name, x = var1 + as_pt(10))) +
  # an annotation that is always 10 points inset from the lower right
  annotate("text", 
    x = as_npc(1) - as_pt(10), 
    y = as_pt(10), 
    label = "some label", vjust = 0, hjust = 1
  ) +
  coord_polar()

image

It is a draft only for several reasons:

  1. Several of the proposed changes probably shouldn't live in ggplot2, but in vctrs, grid, or perhaps scales.
  2. This is just a prototype, not a comprehensive, solid, well-tested solution.
  3. While the solution for positional aesthetics (I think) covers most cases, the solution for non-positional aesthetics is only mocked up for geom_point().

Would love to hear folks' thoughts, or if I am barking up the wrong tree...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant