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:
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')
There is some way to change the bar colour without using the fill option, only using scale_fill_manual?
scale_fill_manual
will work only if you have afill
aesthetic insideaes
. But if you don't want to map a data column to the fill aesthetic, why not just set the fill color insidegeom_bar
:geom_bar(stat="identity", fill="lightblue")
? – Apprehensiveaes()
maps aesthetics, but you can set them using normal function arguments. – Tilt