简体   繁体   English

ggplot2-删除R中的尺寸图例

[英]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_pointgeom_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.

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