簡體   English   中英

使用ggplot2更改條形圖中特定條的顏色

[英]Changing colour of particular bars in bar-chart using 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還是很陌生,無法解決! 提前謝謝了。 在此處輸入圖片說明

使用類似

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

代替

scale_fill_discrete(guide='none')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM