Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
scale_identity doesn't play well with guide = "legend" #2112
Comments
|
Can you please generate the reprex using the reprex package so I can see the results inline? |
hadley
added the
reprex
label
Jun 1, 2017
HughParsonage
commented
Jun 12, 2017
|
Output using df <- data.frame(x = 1:2, y = 1, color = c("red", "blue"), size = c(20, 10),
alpha = c(0.8, 0.4))
library(ggplot2)
ggplot(df, aes(x = x, y = y, color = color, size = size)) + geom_point() + scale_size_identity(guide = "legend")
#> Error in !self$na.translate: invalid argument type |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Henrik-P commentedApr 26, 2017
•
edited
To get a legend guide when using
scale_identitywe need to specifyguide = "legend". In addition, "you'll typically* also need to supplybreaksandlabels" (?scale_identity).However, when trying to get legends for
color,fill,shape,sizeandalpha, when usingscale_identity, a correct legend is obtained only forcolor. All other aesthetics generate either an incorrect legend (fill) or an error (shape,sizeandalpha).Some data:
Then try to get legends, without and with specification of
labelsandbreaks.Legends for
colorandfill:The plot itself looks OK for all aesthetics. The legend for
coloris OK, but thefilllegend only displays black points.Legend for
shapeerrors (Error: Continuous value supplied to discrete scale)Legends for
sizeandalphaerror (Error in !self$na.translate : invalid argument type)By accident, I also mapped
alphawhile specifying asizelegend, resulting in analphalegend:* It's unclear what 'typically' means here. At least in my examples, including or excluding
labelsandbreaksmakes no difference.