R 在ggplot中更改熔化df的颜色

R 在ggplot中更改熔化df的颜色,r,ggplot2,R,Ggplot2,我正试图改变以下ggplot的颜色,但发现很难做到这一点 mm <- melt(CashCycle, id= c('Ticker', 'Date')) mm <- mm[mm$variable == "CollectionPeriod" | mm$variable == "DaysofInventory" | mm$variable == "DaysofPayable",] mm$value <- with(mm, ifelse(variable == "DaysofPayab

我正试图改变以下ggplot的颜色,但发现很难做到这一点

mm <- melt(CashCycle, id= c('Ticker', 'Date'))
mm <- mm[mm$variable == "CollectionPeriod" | mm$variable == "DaysofInventory" | mm$variable == "DaysofPayable",]
mm$value <- with(mm, ifelse(variable == "DaysofPayable", -value, value))
ggplot(data = mm, aes(x = Date, y = value, fill = variable)) + 
  geom_bar(stat = 'identity', position = 'dodge') +
  labs(x="Year", y="Days") +
  theme_bw() +
  guides(color=guide_legend("Legend"))

使用
scale\u fill\u手册

ggplot(data = mm, aes(x = Date, y = value, fill = variable)) + 
  geom_bar(stat = 'identity', position = 'dodge') +
  scale_fill_manual(values = c("red", "blue", "orange")) +
  labs(x="Year", y="Days") +
  theme_bw() +
  guides(color=guide_legend("Legend"))
谢谢它工作得很好!:)下次将记住
scale\u fill\u manual()
ggplot(data = mm, aes(x = Date, y = value, fill = variable)) + 
  geom_bar(stat = 'identity', position = 'dodge') +
  scale_fill_manual(values = c("red", "blue", "orange")) +
  labs(x="Year", y="Days") +
  theme_bw() +
  guides(color=guide_legend("Legend"))