如题,用ggplot2 画图,用scale_fill_discrete()设置了颜色,然后要修改图例的时候又用了scale_fill_discrete(),这样颜色改不过来,提示”Scale for 'fill' is already present. Adding another scale for 'fill', which will replace
the existing scale.“
要怎么设置颜色的同时改变图例的标签呢?我的代码如下:
p<-ggplot(ToothGrowth,aes(x=dose,y=len,fill=supp))+geom_boxplot()+guides(fill=guide_legend(title=NULL))+scale_fill_brewer(palette="Set3")+
theme(legend.position =c(0.94,0.92),legend.background = element_rect(size =0.5, colour = "black"))+scale_fill_discrete(labels=c(a,b))