在ggplot中更改条形图的颜色

时间:2016-09-29 11:39:50

标签: r ggplot2

 errorBar <- ggplot(ErrorAnalDF, aes(Task, ErrorPer, colour = Position))
    errorBar + stat_summary(fun.y = mean, geom = "bar", position = "dodge", fill = "blue") +
      stat_summary(fun.data = mean_cl_normal, geom = "errorbar", position = position_dodge(width = 0.90), width = 0.2) +
     labs(x = "Task", y = "Error Percentage") + facet_wrap(~MuBack) 

enter image description here

如何为Head和Tail的条形填充(蓝色)获得不同的颜色,就像我对错误条和边框一样? 我试过errorBar + stat_summary(fun.y = mean, geom = "bar", position = "dodge", fill = c("red","blue") 或者添加填充labs(x = "Task", y = "Error Percentage", fill="Position")

//编辑:使用fill代替colour

errorBar <- ggplot(ErrorAnalDF, aes(Task, ErrorPer, fill = Position))

给了我这个讨厌的图表 enter image description here

1 个答案:

答案 0 :(得分:2)

在第一个fill=stat.summary使用ggplot(..., aes())而不是fill = position

中留出colour = position
errorBar <- ggplot(ErrorAnalDF, aes(Task, ErrorPer, fill = Position))
errorBar + stat_summary(fun.y = mean, geom = "bar", position = "dodge") +
  stat_summary(fun.data = mean_cl_normal, geom = "errorbar", position = position_dodge(width = 0.90), width = 0.2) +
 labs(x = "Task", y = "Error Percentage") + facet_wrap(~MuBack)

enter image description here