Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scale_fill_manual is not working in geom_bar

I'm trying to change the color in a barplot in ggplot2 using scale_fill_manual, but for some reason only works if i use the fill option inside aesthetics. I made an example:

library(ggplot2)
library(dplyr) 
iris %>% ggplot(aes(x=Sepal.Width,y=Sepal.Length))+
geom_bar(stat="identity") + scale_fill_manual(values='lightblue')

Here is the result, no changing in the color: enter image description here

Now, using the fill option inside aesthetics, it works:

iris %>% ggplot(aes(x=Sepal.Width,y=Sepal.Length, fill=factor(2) ))+
geom_bar(stat="identity")+scale_fill_manual(values='lightblue')

enter image description here

There is some way to change the bar colour without using the fill option, only using scale_fill_manual?

like image 338
Roberto Avatar asked Jul 18 '16 18:07

Roberto


1 Answers

You need to define fill inside your aes .

like image 93
SmallChess Avatar answered Oct 19 '22 18:10

SmallChess