geom errorbar的手动比例尺颜色

geom errorbar的手动比例尺颜色,r,colors,ggplot2,errorbar,R,Colors,Ggplot2,Errorbar,我在尝试将errorbars设置为手动颜色以遵循我为积分设置的颜色方案时遇到问题。基本上,我希望每个errorbar的颜色与其关联点的填充颜色相匹配 创建数据帧 mean<-c(4,5,6,7) CI<-c(0.5,0.4,0.3,0.2) stress<-c(1,2,3,4) a<-c(10,10,20,20) b<-c(7.5,7.5,8,8) data<-data.frame(mean,CI,stress,a,b) mean适合我 ggplot(dat

我在尝试将errorbars设置为手动颜色以遵循我为积分设置的颜色方案时遇到问题。基本上,我希望每个errorbar的颜色与其关联点的填充颜色相匹配

创建数据帧

mean<-c(4,5,6,7)
CI<-c(0.5,0.4,0.3,0.2)
stress<-c(1,2,3,4)
a<-c(10,10,20,20)
b<-c(7.5,7.5,8,8)
data<-data.frame(mean,CI,stress,a,b)
mean适合我

ggplot(data, aes(a, mean)) +
    geom_point()+
    geom_errorbar(aes(ymax=mean+CI,ymin=mean-CI, color=factor(stress)), width=0.3)+
    scale_color_manual("Stress", breaks=c(1,2,3,4),values=c("#0072B2", "#009E73", "#E69F00", "#D55E00"))+
    geom_point(aes(fill=factor(stress)),size=8, shape=21)+
    scale_fill_manual("Stress",breaks=c(1,2,3,4),values=c("#0072B2", "#009E73", "#E69F00", "#D55E00"))+
    scale_x_continuous("Level A",breaks=c(10,20))+
    ylab(expression("Level B"))+
    theme_bw(17)

在您第一次尝试手动将颜色设置为
geom\u errorbar时,我修改了
geom\u errorbar(aes(ymax=mean+CI,ymin=mean-CI,color=factor(stress)),宽度=0.3)
。控制柄的颜色与填充相同。这就是你想要的吗?我想让把手和填充物的颜色一样,是的。然而,我仍然没有得到正确的颜色的处理。它们是彩色的,但与点的填充不匹配。
p<- ggplot(data, aes(a, mean))
    p+geom_point()+
      geom_errorbar(aes(ymax=mean+CI,ymin=mean-CI), width=0.3, color=factor(stress))+
scale_color_manual("Stress", breaks=c(1,2,3,4),values=c("#0072B2", "#009E73", "#E69F00", "#D55E00"))+
      geom_point(aes(fill=factor(stress)),size=8, shape=21)+
      scale_fill_manual("Stress",breaks=c(1,2,3,4),values=c("#0072B2", "#009E73", "#E69F00", "#D55E00"))+
      scale_x_continuous("Level A",breaks=c(10,20))+
      ylab(expression("Level B"))+
      theme_bw(17)

p<- ggplot(data, aes(a, mean))
        p+geom_point()+
          geom_errorbar(aes(ymax=mean+CI,ymin=mean-CI), width=0.3, color=factor(stress))+
    scale_fill_manual("Stress", breaks=c(1,2,3,4),values=c("#0072B2", "#009E73", "#E69F00", "#D55E00"))+
          geom_point(aes(fill=factor(stress)),size=8, shape=21)+
          scale_fill_manual("Stress",breaks=c(1,2,3,4),values=c("#0072B2", "#009E73", "#E69F00", "#D55E00"))+
          scale_x_continuous("Level A",breaks=c(10,20))+
          ylab(expression("Level B"))+
          theme_bw(17)
ggplot(data, aes(a, mean)) +
    geom_point()+
    geom_errorbar(aes(ymax=mean+CI,ymin=mean-CI, color=factor(stress)), width=0.3)+
    scale_color_manual("Stress", breaks=c(1,2,3,4),values=c("#0072B2", "#009E73", "#E69F00", "#D55E00"))+
    geom_point(aes(fill=factor(stress)),size=8, shape=21)+
    scale_fill_manual("Stress",breaks=c(1,2,3,4),values=c("#0072B2", "#009E73", "#E69F00", "#D55E00"))+
    scale_x_continuous("Level A",breaks=c(10,20))+
    ylab(expression("Level B"))+
    theme_bw(17)