Nis*_*ant 5 r bar-chart ggplot2
我有以下数据:
df
rowname repo
1 revrepo 0.888
2 bankrate 0.402
3 CRR 0.250
4 Callrate 0.723
5 WPI 0.049
6 GDP -0.318
7 FED 0.110
8 width 0.209
9 nse 0.059
10 usd 0.185
Run Code Online (Sandbox Code Playgroud)
我正在绘制小节,如下所示:
df %>% mutate(rowname = factor(rowname, levels = rowname[order(repo)])) %>%
ggplot(aes(x = rowname, y = repo)) +
geom_bar(stat = "identity") +
ylab("Correlation with repo") +
xlab("Independent Variable")
Run Code Online (Sandbox Code Playgroud)
我想将负极条涂成红色,将所有正极条涂成灰色。
小智 4
写 Andrey Kolyadin 评论作为解决方案,以使其不再显示为未回答的问题:
geom_bar(aes(fill = repo < 0), stat = "identity") + scale_fill_manual(guide = FALSE, breaks = c(TRUE, FALSE), values=c("gray", "red"))
Run Code Online (Sandbox Code Playgroud)