I have this code to create a graph shown below. I found most of this code in an answer to a previous question in which the graph is very similar to mine (at the bottom of the page).
> 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)))
How do I adapt this so the bars with a positive NAO index (ie currently blue) are red, and those below blue?
I'm sure this is likely an easy solution but I'm very new to R and can't figure it out! Many thanks in advance.
Use something like
scale_fill_manual(values=c("blue", "red"), guide=FALSE)
instead of
scale_fill_discrete(guide='none')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.