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

Conversation

Projects
None yet
2 participants
@brianwdavis
Contributor

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

Pass `label` to `draw_key_text`
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

This comment has been minimized.

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).

Update NEWS.md
Added description for issue #2458
@brianwdavis

This comment has been minimized.

Contributor

brianwdavis commented Feb 20, 2018

Added under the Scales section.

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

2 of 4 checks passed

codecov/patch 0% of diff hit (target 74.98%)
Details
codecov/project 74.96% (-0.02%) compared to 39e4a3b
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@hadley

This comment has been minimized.

Member

hadley commented Apr 27, 2018

Thanks!

@lock

This comment has been minimized.

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.