scale_fill_manual is not working in geom_bar

让人想犯罪 __ 提交于 2021-02-16 13:15:14

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!