Skip to content

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

Merged
yutannihilation merged 7 commits into
tidyverse:masterfrom
yutannihilation:fix/issue-3262-limit-scale-manual
Jan 6, 2020
Merged

yutannihilation merged 7 commits into
tidyverse:masterfrom
yutannihilation:fix/issue-3262-limit-scale-manual

Conversation

@yutannihilation

@yutannihilation yutannihilation commented Dec 22, 2019 •

Copy link
Copy Markdown
Member

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

@thomasp85 thomasp85 left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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