Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof-of concept support for unit() throughout ggplot2 #5610

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

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.

None yet

1 participant