2014-03-05 295 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

簡單有效!非常感謝。 –