scale_fill_manual在geom_bar中不起作用 [英] scale_fill_manual is not working in geom_bar
本文介绍了scale_fill_manual在geom_bar中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用scale_fill_manual来更改ggplot2中的小节中的颜色,但是由于某些原因,只有在我使用美学内的填充选项时才起作用.我举了一个例子:
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')
有什么方法可以只使用scale_fill_manual而不使用填充选项来更改条形颜色?
There is some way to change the bar colour without using the fill option, only using scale_fill_manual?
推荐答案
您需要在 aes
中定义 fill
.
这篇关于scale_fill_manual在geom_bar中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文