Closed
Description
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 thelabel
attributeG
, 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
Metadata
Metadata
Assignees
Labels
No labels