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

Feature request: accept data.frame as scale labels #6090

Open
teunbrand opened this issue Sep 7, 2024 · 0 comments · May be fixed by #6076
Open

Feature request: accept data.frame as scale labels #6090

teunbrand opened this issue Sep 7, 2024 · 0 comments · May be fixed by #6076

Comments

@teunbrand
Copy link
Collaborator

This is a very niche and selfish problem as I'm trying some stuff out in {gguidance}.
It somewhat relates to #6076 a bit, but I'd like the following code:

library(ggplot2)

p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  scale_x_continuous(
    breaks = 2:7,
    labels = data.frame(foo = LETTERS[1:6], bar = 1:6)
  )

get_guide_data(p, aesthetic = "x")
#> Error in `scale_x_continuous()`:
#> ! `breaks` and `labels` have different lengths.

Created on 2024-09-07 with reprex v2.1.1

To return the following data.frame (note that the .label column is a nested data.frame rather than two separate .label.foo and .label.bar columns):

#>           x .value .label.foo .label.bar y
#> 1 0.1127946      2          A          1 0
#> 2 0.2811448      3          B          2 0
#> 3 0.4494949      4          C          3 0
#> 4 0.6178451      5          D          4 0
#> 5 0.7861953      6          E          5 0
#> 6 0.9545455      7          F          6 0

The justification I have for this is that {vctrs} treats data.frames as vectors where rows are treated as elements. We don't really have a good reason to deviate from this behaviour.

@teunbrand teunbrand changed the title Feature request: accept data.frame labels Feature request: accept data.frame as labels Sep 7, 2024
@teunbrand teunbrand changed the title Feature request: accept data.frame as labels Feature request: accept data.frame as scale labels Sep 7, 2024
@teunbrand teunbrand linked a pull request Sep 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant