-1

I'm having trouble setting the colors of my bar graph. Here is the code I am using. When the graph prints, all the bars default to gray.

a<- c("a", "b", "c", "d", "e")
b<- rnorm(5)
A<-data.frame(a,b)
group.colors <- c(a= "blue", 
                  b= "orange", 
                  c= "blue",
                  d = "orange", 
                  e = "orange")
A%>%ggplot(aes(a)) +
  geom_bar() +
  scale_fill_manual(group.colors)
Tony
  • 9
  • 2

1 Answers1

1

You need to map a variable to the fill aesthetic, otherwise changing scale_fill_manual has no effect since there is no no scale which could be filled:

ggplot(A, aes(a, fill = a)) +
  geom_bar() +
  scale_fill_manual(values = group.colors)
Thomas K
  • 3,242
  • 15
  • 29