-
Notifications
You must be signed in to change notification settings - Fork 20
by_aesthetics.R refactor
#539
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
by_aesthetics.R refactor
#539
Conversation
grantmcdermott
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor namespace redundancies but otherwise LGTM.
Feel free to (squash and) merge when you're actioned.
Thanks Vincent!
R/by_aesthetics.R
Outdated
|
|
||
| # Map numeric indices to palette colors (unless ordered) | ||
| if (!ordered && is.numeric(cols)) { | ||
| base_pal = grDevices::palette() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already import palette as part of our namespace, no?
R/by_aesthetics.R
Outdated
|
|
||
| if (is.null(palette_choice)) { | ||
| # Default palette selection (alpha applied at end) | ||
| base_pal = grDevices::palette() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
R/by_aesthetics.R
Outdated
| if (ngrps <= length(base_pal) && !ordered && !gradient) { | ||
| cols = base_pal[seq_len(ngrps)] | ||
| } else if (ngrps <= 8 && !ordered) { | ||
| cols = grDevices::palette.colors(n = ngrps, palette = "R4") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already in namespace.
R/by_aesthetics.R
Outdated
| } else if (ngrps <= 8 && !ordered) { | ||
| cols = grDevices::palette.colors(n = ngrps, palette = "R4") | ||
| } else if (!gradient && !ordered) { | ||
| cols = grDevices::hcl.colors(n = ngrps, palette = "Viridis") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Namespace
R/by_aesthetics.R
Outdated
| args = list(n = ngrps, palette = palette, alpha = alpha) | ||
| # Restricted viridis for gradient/ordered (excludes extreme ends) | ||
| cols = colorRampPalette( | ||
| grDevices::hcl.colors(n = 100, palette = "Viridis")[11:90], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Namespace
R/by_aesthetics.R
Outdated
| hcl.colors(n = 100, palette = "Viridis", alpha = alpha)[(100 * 0.1 + 1):(100 * 0.9)], | ||
| alpha = TRUE | ||
| )(ngrps) | ||
| grDevices::hcl.colors(max(cols))[cols] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace
Streamlining, DRY, and simplification for the
by_aesthetics()functions.Removed about 60 lines of code and made things (arguably) clearer.
TBC, there's absolutely no rush to review this. I just found some time to work on this (with Claude) this morning.