2

好的,我这里有两个问题,我不知道如何解决:

1) 误差条不会与图表上的条对齐。2)条的颜色用我想要的颜色勾勒出来,但由于某种原因用黑色填充。

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")

我的数据框是“Cycle1”...我很抱歉不知道如何正确发布数据。

    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
4

1 回答 1

2

color只解决了酒吧的外面。fill决定了它们内部的颜色。

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")

我确定您已经注意到了,但我简化了您的代码。您无需在Oreo_Cycle1每次拨打电话时都指定。

于 2015-12-11T23:19:22.117 回答