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

geom_rect() can derive corners from x/width or y/height #5862

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

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #5861.

Briefly, geom_rect() can derive the xmin/xmax/ymin/ymax parameters from x/width and y/height parameters.

The trickiest thing with this PR is what is understood as 'required aesthetics'. Currently, all the parameters mentioned above are 'optional aesthetics' and the corners ( xmin/xmax/ymin/ymax) are marked as 'non missing aesthetics'. The corners are subjected to a second check_required_aesthetics() to throw a warning.

A demo from the issue:

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

p <- ggplot(
  presidential,
  aes(xmin = start, xmax = end, y = forcats::fct(name))
)

p + geom_rect(height = 0.8)

However, if there is only 1 known aesthetic per position (in the example, just the y aesthetic), it'll throw an error due to missing aesthetics. It might be worth considering throwing a more tailored warning in this case.

p + geom_rect()
#> Error in `geom_rect()`:
#> ! Problem while setting up geom.
#> ℹ Error occurred in the 1st layer.
#> Caused by error in `setup_data()` at ggplot2/R/ggproto.R:190:17:
#> ! `geom_rect()` requires the following missing aesthetics: ymin and
#>   ymax.

Created on 2024-04-24 with reprex v2.1.0

@teunbrand
Copy link
Collaborator Author

Possibly CI failing due to the R4.4.0 release? Will run again tomorrow.

@teunbrand
Copy link
Collaborator Author

I'm not really content with this PR as it seems like abusing the various aesthetics fields in the ggproto class. I'll put this as a draft for now.

@teunbrand teunbrand marked this pull request as draft April 26, 2024 12:40
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: flexible parametrisation of rectangles
1 participant