0

I'm working on a statistical report whose objective is the detection of differences among treatment A, treatment B and a control group after 6 and 8 weeks.

I have this two kinds of bar plots:

enter image description here

enter image description here

As you can see the bar color depends on the group therefore I need a conditional bar color.

Nevertheless I would like to have the same color for each group regardless of the plot, that is , to have "control group" always in red, group "A" always in green and group "B" always in blue (or vice versa, It doesn't matter).

Therefore, I need a conditional color depending on the group and also some kind of manual instruction since ggplot automatically sets the conditionals colors.

Here is the code I've used:

First plot:

   Treatment   Week     Mean
1         A  8 weeks   77.42
2         B  8 weeks   75.09
3         A  6 weeks   88.39
4         B  6 weeks   89.04


       ggplot(data=d, aes(x=Week, y=as.numeric(as.character(Mean)),    fill=Treatment)) 
+ geom_bar(stat="identity", position=position_dodge()) +ylab("Estimated Mean")
+ geom_errorbar(aes(
ymin=as.numeric(as.character(Mean))-as.numeric(as.character(sd)),
       ymax=as.numeric(as.character(Mean))+as.numeric(as.character(sd))), width=.2,
                  position=position_dodge(.9))

Second plot:

      Treatment    Week     Mean
1   Control     8 weeks    77.4
2         A     8 weeks    75.09
3         B     8 weeks    88.39
4   Control     6 weeks    89.04
5         A     6 weeks    77.42
6         B     6 weeks    75.09

ggplot(data=d, aes(x=Week, y=as.numeric(as.character(Mean)), fill=Treatment)) +
  geom_bar(stat="identity", position=position_dodge()) +ylab("Estimated Mean")+
geom_errorbar(aes(
  ymin=as.numeric(as.character(Mean))-as.numeric(as.character(sd)),
   ymax=as.numeric(as.character(Mean))+as.numeric(as.character(sd))), width=.2,
              position=position_dodge(.9))

Thank you very much.

Leibnitz Crew
  • 61
  • 1
  • 5

0 Answers0