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

Fix limits argument of scale_{colour,fill}_manual() #3685

Conversation

yutannihilation
Copy link
Member

@yutannihilation yutannihilation commented Dec 22, 2019

Fix #3262

At the time of #3262 (comment), I thought this should be fixed in manual_scale(). But it turns out this is a bug of ScaleDiscrete; the if block below uses limits only when pal is named:

ggplot2/R/scale-.r

Lines 778 to 783 in e6cbcc1

if (is.null(names(pal))) {
pal_match <- pal[match(as.character(x), limits)]
} else {
pal_match <- pal[match(as.character(x), names(pal))]
pal_match <- unname(pal_match)
}

I see no reason to ignore limits here. (This code has been here since Scale was first implemented (1877b6d), so there might have been some limitation?) This PR fixes the issue by limiting the pal first before matching it against the supplied values.

@yutannihilation yutannihilation changed the title WIP: fix limits argument of scale_{colour,fill}_manual() Fix limits argument of scale_{colour,fill}_manual() Dec 22, 2019
Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

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

LGTM - if everything checks out after resolving conflicts you are free to merge

@yutannihilation
Copy link
Member Author

Thanks

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.

scale_{colour,fill}_manual(limits = ...) doesn't limit the scale
2 participants