简体   繁体   中英

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. 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.

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))

在此处输入图像描述

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