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

Enable 2D structures as aesthetics #6076

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #4189.

Briefly, this PR would allow people to use 2D structures like matrices, data.frames and tibbles as aesthetics.
We just had to adopt the {vctrs} way of measure sizes and setting names at select places for this to.
Importantly, this does not implement appropriate scales for such aesthetics, but it removes a barrier for extension developers to implement them.

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

df <- mtcars
df$tib <- tibble::tibble(mpg = df$mpg, disp = df$disp)
df$mtx <- cbind(mpg = df$mpg, disp = df$disp)

p <- ggplot(df, aes(cyl, disp, dummy = tib)) +
  geom_point()

layer_data(p)$dummy |> head()
#> Don't know how to automatically pick scale for object of type
#> <tbl_df/tbl/data.frame>. Defaulting to continuous.
#> # A tibble: 6 × 2
#>     mpg  disp
#>   <dbl> <dbl>
#> 1  21     160
#> 2  21     160
#> 3  22.8   108
#> 4  21.4   258
#> 5  18.7   360
#> 6  18.1   225

layer_data(p + aes(dummy = mtx))$dummy |> head()
#>       mpg disp
#> [1,] 21.0  160
#> [2,] 21.0  160
#> [3,] 22.8  108
#> [4,] 21.4  258
#> [5,] 18.7  360
#> [6,] 18.1  225

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

@teunbrand
Copy link
Collaborator Author

I'm unsure why the coverage CI is failing

@teunbrand
Copy link
Collaborator Author

TODO: check errors in scales

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.

Feature request: support for tibble aesthetics
1 participant