Skip to content

Conversation

@vincentarelbundock
Copy link
Collaborator

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.

Copy link
Owner

@grantmcdermott grantmcdermott left a 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!


# Map numeric indices to palette colors (unless ordered)
if (!ordered && is.numeric(cols)) {
base_pal = grDevices::palette()
Copy link
Owner

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?


if (is.null(palette_choice)) {
# Default palette selection (alpha applied at end)
base_pal = grDevices::palette()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

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")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already in namespace.

} 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")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Namespace

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],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Namespace

hcl.colors(n = 100, palette = "Viridis", alpha = alpha)[(100 * 0.1 + 1):(100 * 0.9)],
alpha = TRUE
)(ngrps)
grDevices::hcl.colors(max(cols))[cols]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespace

@vincentarelbundock vincentarelbundock merged commit 3130e7b into grantmcdermott:main Jan 11, 2026
3 checks passed
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.

2 participants