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

Default label is ignored when a mapping is overwritten by a parameter #6003

Closed
yutannihilation opened this issue Jul 17, 2024 · 1 comment · Fixed by #6004
Closed

Default label is ignored when a mapping is overwritten by a parameter #6003

yutannihilation opened this issue Jul 17, 2024 · 1 comment · Fixed by #6004

Comments

@yutannihilation
Copy link
Member

yutannihilation commented Jul 17, 2024

Related to #5879

In the code below, the legend title is chosen differently depending on whether the same aes variable is specified by a parameter outside of aes(). In the second one, I think the title should be either

  • <<< G >>>, because it's specified by the label attribute
  • G, because the second layer is what the color scale is actually for
library(ggplot2)

d <- data.frame(x = 1, y = 2, g = 3)
d2 <- d
colnames(d2) <- c("X", "Y", "G")

attr(d[[1L]], "label") <- "<<< X >>>"
attr(d[[2L]], "label") <- "<<< Y >>>"
attr(d[[3L]], "label") <- "<<< G >>>"

ggplot() +
  geom_point(data = d, aes(x, y, colour = g)) +
  geom_point(data = d2, aes(X, Y, colour = G))

ggplot() +
  geom_point(data = d, aes(x, y, colour = g), colour = "grey") + 
  #                                           ^^^^^^^^^^^^^^^
  #                                             the difference
  geom_point(data = d2, aes(X, Y, colour = G))

Created on 2024-07-17 with reprex v2.1.0

@teunbrand
Copy link
Collaborator

Thanks for posting this! I think the label should be G in this case.
In the first layer, colour = "grey" should rule out any colour-label coming from the first layer.
Thus, the second layer should decide and since d2$G has no label-attribute, it should be G.

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 a pull request may close this issue.

2 participants