问题
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?
回答1:
You need to define fill
inside your aes
.
来源:https://stackoverflow.com/questions/38443563/scale-fill-manual-is-not-working-in-geom-bar