Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 将气泡颜色指定为变量限制了ggplot中的选择_R_Ggplot2_Legend - Fatal编程技术网

R 将气泡颜色指定为变量限制了ggplot中的选择

R 将气泡颜色指定为变量限制了ggplot中的选择,r,ggplot2,legend,R,Ggplot2,Legend,在ggplot中创建气泡图时,我遇到了调整两个独立美学选择的问题,我确信这与我编写情节的方式有关。在下图中,如果我基于如下变量指定气泡的颜色: V1<-rnorm(50) V2<-rnorm(50) V3<-c(rep("A",10),rep("B",10),rep("C",10),rep("D",10),rep("E",10)) V4<-V2+.1 V5<-c(rep("BF1",9),rep("BF2",11),rep("BF3",8),rep("BF4",12

在ggplot中创建气泡图时,我遇到了调整两个独立美学选择的问题,我确信这与我编写情节的方式有关。在下图中,如果我基于如下变量指定气泡的颜色:

V1<-rnorm(50)
V2<-rnorm(50)
V3<-c(rep("A",10),rep("B",10),rep("C",10),rep("D",10),rep("E",10))
V4<-V2+.1
V5<-c(rep("BF1",9),rep("BF2",11),rep("BF3",8),rep("BF4",12),rep("BF5",10))
DF<-data.frame(V1,V2,V3,V4,V5)

ggplot(DF,aes(x=V1,y=V2,size=V4,label=DF$V3,fill=V5),legend=FALSE)+
scale_y_continuous( limits = c(-3, 3))+
scale_x_continuous( limits = c(-3, 3))+
geom_point(color="black",shape=21,alpha=0.5)+
geom_text(size=2)+
theme_bw()+
scale_size(range = c(5, 20))+
scale_colour_brewer(palette="Blues")
V1对于(1)使用
scale\u fill\u brewer(palete=“Blues”)

对于(2)使用
指南(尺寸=指南\图例(override.aes=列表(fill=“black”,alpha=1))



更新:@BenBoker在上面的评论中提出了一个很好的观点。我建议至少,在图例中增加字母:添加到上面的(2):
,color=guide\u图例(override.aes=list(alpha=0.9))
或类似性质的东西

填充和颜色是不同的美学。要减少“粉彩”会有点困难颜色,因为设置
alpha=0.5
会将您使用的任何填充颜色稀释一半。。。尽管@joran指出,使用
scale\u fill\u brewer
而不是
scale\u color\u brewer
会有所帮助。