[英]ggplot2 - removing size legend in R
I want to remove the size 20 legend on the right. 我想删除右侧的20号图例。 Below is my code:
下面是我的代码:
qplot(lingLocation[ind,ind_water_fountain]/lingLocation[ind,1],
lingLocation[ind,ind_soda]/lingLocation[ind,1],
color = lingLocation[ind,ind_frosting]/lingLocation[ind,1], size = 20) +
# opts(legend.position = "none") +
scale_colour_gradient("Frosting %", low = "blue", high = "red") +
ylab("Soda %") +
xlab("Water Fountain %")
Thanks! 谢谢!
Try removing the size=20
argument from the qplot
call, and stick it in a geom_point
call. 尝试从
qplot
调用中删除size=20
参数,并将其geom_point
在geom_point
调用中。
For example, change your code to this: 例如,将您的代码更改为此:
qplot(lingLocation[ind,ind_water_fountain]/lingLocation[ind,1],
lingLocation[ind,ind_soda]/lingLocation[ind,1],
color = lingLocation[ind,ind_frosting]/lingLocation[ind,1]) +
# opts(legend.position = "none") +
scale_colour_gradient("Frosting %", low = "blue", high = "red") +
ylab("Soda %") +
xlab("Water Fountain %") +
geom_point(size=20)
I don't use the qplot
function, but I think that should work. 我不使用
qplot
函数,但我认为应该可以。 I believe ggplot2
adds a scale for every aesthetic call in each geom, which is what qplot
is probably doing. 我相信
ggplot2
会为每个geom中的每个美学调用增加一个比例,这就是qplot
可能正在做的事情。 But since you are applying the size to all points, having the size parameter outside of the aes
should achieve the same effect, and the size=20
will not generate a legend for it (I think). 但是,由于将大小应用于所有点,因此将尺寸参数设置为
aes
之外应该会达到相同的效果,并且size=20
不会为其生成图例(我认为)。 And geom_point
should inherit the aesthetics from qplot
(I hope). 而
geom_point
应继承的美学qplot
(我希望)。
Let me know if this works! 让我知道这个是否奏效!
EDIT: 编辑:
I just tested it. 我刚刚测试过。 Placing size inside
geom_point
should work. 将大小放在
geom_point
应该可以。 However, the size settings from inside qplot
seem to differ from the size settings when called from geom_point
, so maybe setting a smaller size inside geom_point
should do the trick (say, geom_point(size=5)
) 但是,从
qplot
调用时, geom_point
内部的大小设置似乎与大小设置不同,因此也许可以在geom_point
内部设置较小的大小来geom_point
(例如geom_point(size=5)
)。
qplot
assumes that the size
specification is a mapping and so creates a scale. qplot
假定size
规格是一个映射,因此会创建一个比例。 Here, you just want to set it to 20, so replace size = 20
with size = I(20)
. 在这里,您只想将其设置为20,所以将
size = 20
替换为size = I(20)
。 That sets the size and does not create a scale (and probably makes the points bigger than you anticipated). 这会设置大小,并且不会创建比例(并且可能会使点比您预期的要大)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.