2014-03-05 292 views
1

我使用此代码创建如下所示的图形。我在前面的question的回答中发现了大部分代码,其中图形与我的非常相似(在页面的底部)。使用ggplot2更改条形图中特定条形的颜色

> x = ggplot(df, aes(x=Year, y=NAO_Index, width=.8)) + 
geom_bar(stat="identity", aes(fill=NAO_Index>0), position='identity') + 
theme_bw() + scale_fill_discrete(guide='none') + 
ylab("NAO Index") + 
ggtitle("NAO Index between 1860 and 2050") + 
scale_x_continuous(breaks=c(seq(1860,2050,10))) 

如何适应这个如此具有正NAO指数棒(即目前蓝)是红色的,和那些下面是蓝色的?

我敢肯定这可能是一个简单的解决方案,但我对R很陌生,无法弄清楚!提前谢谢了。 enter image description here

回答

2

使用类似

scale_fill_manual(values=c("blue", "red"), guide=FALSE) 

代替

scale_fill_discrete(guide='none') 
+0

简单有效!非常感谢。 –