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

Handle fine-grained show.legend properly #3490

Conversation

yutannihilation
Copy link
Member

Fix #3461

Currently, guide_geom.colorbar() doesn't follow the way how guide_geom.legend() handles the case when show.legend is a named logical vector. This PR fixes it.

Besides, this PR also fixes guide_geom.legend() to handle multiple logicals, which I should have fixed #3163.

library(dplyr, warn.conflicts = FALSE)

devtools::load_all("~/repo/R/ggplot2/")

tribble(
  ~x1, ~y1, ~x2, ~y2, ~id, ~id_int,
  1,   1,   2,   2, "A",       1,
  2,   2,   3,   3, "B",       2
) %>%
  ggplot(aes(xmin = x1, ymin = y1, xmax = x2, ymax = y2, fill = id_int)) +
  geom_rect(show.legend = c(size = FALSE, fill = TRUE))

@yutannihilation yutannihilation changed the title Fix/issue 3461 fine grained show.legend Handle fine-grained show.legend properly Aug 18, 2019
@yutannihilation
Copy link
Member Author

Travis fails on build R<=3.4, where isTRUE() was not tolerant for named TRUE...

# R 3.4.4 on RStudio Cloud

x <- c(a = TRUE, b = FALSE)
is.na(x["no_such_element"])
#> <NA> 
#> TRUE
isTRUE(is.na(x["no_such_element"]))
#> [1] FALSE

Created on 2019-08-18 by the reprex package (v0.2.1)

# 1. show_legend can be multiple NAs
# 2. isTRUE() was not tolerant for a named TRUE
show_legend <- show_legend[!is.na(show_legend)]
include <- length(show_legend) == 0 || any(show_legend)
Copy link
Member

Choose a reason for hiding this comment

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

Why does an empty show_legend lead to inclusion here?

Copy link
Member Author

Choose a reason for hiding this comment

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

iiuc, guide_geom() shows a legend if

  1. the layer's mapping contains any of the corresponding aes and
  2. the user does not explicitly choose not to show the legend

So, the absence of the corresponding show.legend should be translated as inclusion.

Does this answer your question? Sorry, I might not get your point....

Copy link
Member

Choose a reason for hiding this comment

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

You are right - I'm probably just tired

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. Sorry for making you busy with reviewing pull requests :)

@yutannihilation yutannihilation merged commit b68912d into tidyverse:master Aug 26, 2019
@yutannihilation yutannihilation deleted the fix/issue-3461-fine-grained-show.legend branch August 26, 2019 13:48
@lock
Copy link

lock bot commented Feb 22, 2020

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 Feb 22, 2020
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.

Continuous fill does not obey fine-grained show.legend settings
2 participants