简体   繁体   中英

Irrelevant legend information in ggplot2

When running this code (go ahead, try it):

library(ggplot2)
(myDat <- data.frame(cbind(VarX=10:1, VarY=runif(10)), 
    Descrip=sample(LETTERS[1:3], 10, replace=TRUE)))
ggplot(myDat,aes(VarX,VarY,shape=Descrip,size=3)) + geom_point()

... the "size=3" statement does correctly set the point size. However it causes the legend to give birth to a little legend beneath it, entitled "3" and containing nothing but a big dot and the number 3.

This does the same

ggplot(myDat,aes(VarX,VarY,shape=Descrip)) + geom_point(aes(size=3)) 

Yes, it is funny. It would have driven me insane a couple hours ago if it weren't so funny. But now let's make it stop.

That's because it's interpreting it as an aesthetic mapping rather than a constant. This works I think:

ggplot(myDat,aes(VarX,VarY,shape=Descrip)) + geom_point(size=3)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM