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

Pass label to draw_key_text #2458

Merged
merged 2 commits into from Apr 27, 2018
Merged

Pass label to draw_key_text #2458

merged 2 commits into from Apr 27, 2018

Conversation

brianwdavis
Copy link
Contributor

@brianwdavis brianwdavis commented Feb 20, 2018

To override the default "a" in the label of a text legend: first check if data$label has anything in it; if not, use "a" as before. However, if the user sets a label within guide_legend(override.aes = list(label = "foo")), then use that label or vector of labels as the first arg of textGrob.

Motivation

This is a relatively common request on SO, to wit: https://stackoverflow.com/questions/48892982/change-key-letter-in-legend-of-ggplot

The problem

The current version of draw_key_text has a hardcoded "a" as the first arg of textGrob.

Example using the fix

ggplot(mtcars, aes(mpg, wt, color = factor(am), label = disp)) +
  geom_text() +
  guides(color = guide_legend(override.aes = list(label = c("a", "m"))))

image

To override the default "a" in the label of a text legend: first check if `data$label` has anything in it; if not, use "a" as before. However, if the user sets a label within `guide_legend(override.aes = list(label = "foo"))`, then use that label or vector of labels as the first arg of `textGrob`.
@hadley
Copy link
Member

hadley commented Feb 20, 2018

Nice!

Can you please add a bullet to NEWS? It should briefly describe the change (starting with name of the function), and crediting yourself with (@yourname, #issuenumber).

Added description for issue tidyverse#2458
@brianwdavis
Copy link
Contributor Author

Added under the Scales section.

@hadley hadley merged commit 1d537ce into tidyverse:master Apr 27, 2018
@hadley
Copy link
Member

hadley commented Apr 27, 2018

Thanks!

@lock
Copy link

lock bot commented Oct 24, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Oct 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants