简体   繁体   English

自定义 ggplot2 中连续大小的图例

[英]Customize legend for continuous size in ggplot2

I was trying to emphasize some specific size as a reference in my legend.我试图在我的传说中强调一些特定的尺寸作为参考。 I tried scale_size_continuous and scale_size_manual without any luck.我试过scale_size_continuousscale_size_manual没有任何运气。 Below is a toy example, is there anyone who can help with it?下面是一个玩具示例,有没有人可以帮忙?

set.seed(926)
dat.toy <- data.frame(x1 = rnorm(100),
                      x2 = rnorm(100),
                      x3 = factor(sample(1:5,100,replace = T)),
                      x4 = factor(sample(1:4,100,replace = T)))
require(ggplot2)

ggplot(dat.toy,aes(x=x3,y=x4,colour = x1, size = x2)) + 
  geom_point()

阴谋

The desired result should be able to customize (amplify or shrink) the size of the circle, add the size of the circle for -3 , delete (hide) the size of the circle for 2 in the legend.期望的结果应该能够自定义(放大或缩小)圆圈的大小,在图例中添加-3的圆圈大小,删除(隐藏) 2的圆圈大小。

Thanks in advance.提前致谢。

You could try something like this?你可以试试这样的东西吗?

require(ggplot2)

ggplot(dat.toy,aes(x=x3,y=x4, color = x1)) + 
  geom_point(aes(size=x2))+
  geom_jitter()+
  scale_size(range = c(-2,4))

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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