3

I working on a ggplot2 plot of the following data:

means <- c(2.4,3,3,3.16,2.5,2.5,3,4.5)
sds <- c(1.0,1.2,1.0,1.1,2.1,0.7,2.8,0.7)
teams <- c(1,1,1,1,2,2,2,2)
scales <- c(1,2,3,4,1,2,3,4)

datas <- data.frame(teams, scales, means, sds)

Thanks to a very active helper, the plot looks like this:

graph <- 
    ggplot(data=datas,  aes(scales, y=means, group=teams)) + 
    geom_bar(aes(fill=teams), stat="identity", 
             position="dodge") + 
    geom_errorbar(aes(ymin= means - sds, ymax = means + sds, width=0.2), 
                  position=position_dodge(width=0.90)) +
    coord_flip()

Now I want to change the colour of the bars into special colours. I got a hint that scale_fill_manual would do it (I tried scale_fill_manual(values= c('#0023a0', '#f9a635'))+...) but all I get is an error (Continuous value supplied to discrete scale). Any ideas?

4

1 回答 1

8
ggplot(data = datas,  aes(scales, y = means, group = teams)) + 
    geom_bar(aes(fill = as.factor(teams)), stat = "identity", 
             position = "dodge") + 
    geom_errorbar(aes(ymin = means - sds, ymax = means + sds, width=0.2), 
                  position = position_dodge(width = 0.90)) +
    coord_flip()  + scale_fill_manual("Teams",values = c('#0023a0', '#f9a635'))
于 2012-10-01T13:47:14.880 回答