You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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))
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.
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 forCreated on 2024-07-17 with reprex v2.1.0
The text was updated successfully, but these errors were encountered: