R 更改ggplot在几何图形栏中绘制边框颜色的顺序

R 更改ggplot在几何图形栏中绘制边框颜色的顺序,r,ggplot2,R,Ggplot2,当我希望在分类单元周围始终有完整的红色矩形来表示“B”的效果时,如何对其进行编码?scale\u*\ u manual函数接受已命名或未命名的值参数,因此您可以使用值=c(A=“black”,B=“red”)或根据需要进行设置 df <- data.frame(Taxon=c("A", "B", "C"), Counts=c(0.1,0.5,0.4), Treatment=rep("X1",3),

当我希望在分类单元周围始终有完整的红色矩形来表示“B”的效果时,如何对其进行编码?

scale\u*\ u manual
函数接受已命名或未命名的
参数,因此您可以使用
值=c(A=“black”,B=“red”)
或根据需要进行设置
df <- data.frame(Taxon=c("A", "B", "C"),
                 Counts=c(0.1,0.5,0.4),
                 Treatment=rep("X1",3),
                 Effect=factor(c("A","B","A")))
df$Effect <- factor(df$Effect, levels=c("A","B"), ordered=T)

ggplot() + 
  geom_bar(data=df, aes(x = Treatment, y = Counts, fill = Taxon, colour=Effect), 
           stat="identity", position="fill", width=0.5)+
  scale_fill_manual("",values=c("gold", "green","yellow"))+
  scale_color_manual("",values=c("black","red"))
df$Effect <- factor(df$Effect, levels=c("B","A"), ordered=T)


ggplot() + 
  geom_bar(data=df, aes(x = Treatment, y = Counts, fill = Taxon, colour=Effect), 
           stat="identity", position="fill", width=0.5)+
  scale_fill_manual("",values=c("gold", "green","yellow"))+
  scale_color_manual("",values=c("black","red"))