ggplot2中不相关的图例信息 [英] Irrelevant legend information in ggplot2

查看:95
本文介绍了ggplot2中不相关的图例信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行此代码(继续,尝试它):

pre $ library $ g
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()

...size = 3语句确实正确设置了点的大小。然而它导致这个传说诞生了一个名为3的小传说,并且只包含一个大圆点和数字3.除此之外,它的确也是如此

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

是的,这很有趣。如果它不那么有趣,它会在几个小时前让我疯狂。但现在让我们停下来。

解决方案

这是因为它将它解释为审美映射而不是常量。这个作品我认为:

pre $ g $ p $ ggplot(myDat,aes(VarX,VarY,shape = Descrip))+ geom_point(size = 3 )


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)

这篇关于ggplot2中不相关的图例信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆