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

Add the possibilty for show.legend to be a vector #1798

Closed
Tutuchan opened this issue Sep 29, 2016 · 1 comment
Closed

Add the possibilty for show.legend to be a vector #1798

Tutuchan opened this issue Sep 29, 2016 · 1 comment

Comments

@Tutuchan
Copy link
Contributor

@Tutuchan Tutuchan commented Sep 29, 2016

In geom_* functions, the show.legend parameter can be either TRUE or FALSE and applies to the whole layer.

When TRUE (the default), lines appear in the legends for factor(vs) (colour) and factor(am) (linetype):

library(ggplot2)

ggplot(mtcars) +
  geom_point(aes(mpg, qsec, colour = factor(vs), shape = factor(am))) + 
  geom_line(aes(mpg, qsec, colour = factor(vs), linetype = factor(am)))

image

When FALSE, lines do not appear in the legend at all:

ggplot(mtcars) +
  geom_point(aes(mpg, qsec, colour = factor(vs), shape = factor(am))) + 
  geom_line(aes(mpg, qsec, colour = factor(vs), linetype = factor(am)), show.legend = FALSE)

image

The idea would be to provide a named logical vector to show.legend in order to specify which aesthetic are shown in the legend for this layer, like so, where lines appear in the legend for factor(am) but not for factor(vs):

ggplot(mtcars) +
    geom_point(aes(mpg, qsec, colour = factor(vs), shape = factor(am))) + 
    geom_line(aes(mpg, qsec, colour = factor(vs), linetype = factor(am)), 
              show.legend = c(colour = FALSE))

image

Please let me know if you think this could be a useful addition. I tried my hand at implementing this (see here) and this works (except when using color instead of colour) but I'm sure there is a better way if you decide to implement it.

@hadley
Copy link
Member

@hadley hadley commented Jan 25, 2017

This seems like a good idea, but unfortunately it's not high enough on my priority list that I will implement it myself. However, I'd be happy to review a PR.

Loading

@hadley hadley closed this Jan 25, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants