Swanny
Swanny

Reputation: 189

ggplot error bars problems

Okay I have two problems here that I can't figure out how to fix:

1) The error bars won't line up with the bars on the graph. 2) The color of the bars are outlined with the color I want but filled in with black for some reason.

Oreo_Cycle1 <- Cycle1[Cycle1$Food_Type=="Oreo",]
Chow_Cycle1 <- Cycle1[Cycle1$Food_Type=="Chow",]
#Oreo graph
Oreop <- ggplot(Oreo_Cycle1, aes(as.factor(Oreo_Cycle1$Time_Point),           
Oreo_Cycle1$Amount, color=Oreo_Cycle1$Treatment, ymax=Oreo_Cycle1$Amount +  
Oreo_Cycle1$SEM, ymin=Oreo_Cycle1$Amount - Oreo_Cycle1$SEM))

Oreop + geom_bar(position="dodge", width=0.5, stat="identity") +   
scale_color_manual("Treatment Group", labels=c("Control", "HD+S", "HD+S+E"),  
values=c("#CC0000","#00CC00","#0000CC")) + xlab("Timepoint (h)") + ylab("HP 
consumed (g)") + geom_errorbar(color="black")

My data frame is "Cycle1"...I apologize for not knowing how to post data correctly.

    Treatment   Time_Point  Food_Type   Amount  SEM
1   Control 2   Chow    0.04    0.03078518
2   Control 2   Oreo    0.30    0.21523067
3   Control 4   Chow    0.12    0.15365003
4   Control 4   Oreo    0.66    0.25360880
5   Control 24  Chow    0.20    0.21483433
6   Control 24  Oreo    3.77    0.38665132
7   Control 48  Chow    1.06    0.62440275
8   Control 48  Oreo    6.95    0.90266734
9   HD_S    2   Chow    0.07    0.23526903
10  HD_S    2   Oreo    0.45    0.47984846
11  HD_S    4   Chow    0.08    0.22853121
12  HD_S    4   Oreo    0.76    0.39543608
13  HD_S    24  Chow    0.33    0.44038207
14  HD_S    24  Oreo    3.82    0.62123716
15  HD_S    48  Chow    1.20    1.04163442
16  HD_S    48  Oreo    6.97    1.22847374
17  HD_S_E  2   Chow    0.01    0.02874918
18  HD_S_E  2   Oreo    0.37    0.21453791
19  HD_S_E  4   Chow    0.02    0.03232177
20  HD_S_E  4   Oreo    0.79    0.36748428
21  HD_S_E  24  Chow    0.33    0.50731244
22  HD_S_E  24  Oreo    3.55    1.22559695
23  HD_S_E  48  Chow    1.91    1.60747190
24  HD_S_E  48  Oreo    6.82    2.33594378

Upvotes: 2

Views: 154

Answers (1)

black_sheep07
black_sheep07

Reputation: 2368

color only addresses the outside of the bars. fill determines the color inside of them.

ggplot(Oreo_Cycle1, aes(x = as.factor(Time_Point), 
                        y = Amount, 
                        fill = Treatment, 
                        ymax=(Amount + SEM), 
                        ymin=(Amount - SEM)) + 
    geom_bar(position="dodge", width=0.5, stat="identity") +
    scale_fill_manual("Treatment Group", labels=c("Control", "HD+S", "HD+S+E"),  
                       values=c("#CC0000","#00CC00","#0000CC")) + 
    xlab("Timepoint (h)") + ylab("HP consumed (g)") +
    geom_errorbar(color="black")

I'm sure you already noticed, but I simplified your code. You don't need to specify Oreo_Cycle1 every time you make a call.

Upvotes: 2

Related Questions