ggplot2 icon indicating copy to clipboard operation
ggplot2 copied to clipboard

scale_manual warning "no shared levels" could be improved

Open tdhock opened this issue 6 months ago • 1 comments

Related to #5669 which discusses this warning.

I tried adding aes(size) an a geom which already had size defined as a parameter, and I got the following warning:

library(ggplot2)
ggplot()+
  scale_size_manual(values=c(a=2,b=4))+
  geom_point(aes(
    x,x,size=x),
    size=3,
    data=data.frame(x=c('a','b')))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's size values.

Created on 2025-04-15 with reprex v2.1.1

It took me some time before I realized that the solution was to remove size=3.

I would suggest improving the warning to say something like "size has been specified in aes and as a parameter in geom_point; please remove one or the other" which would be much more helpful than the current warning.

Thanks for maintaining ggplot2!

tdhock avatar Apr 15 '25 13:04 tdhock