admin管理员组

文章数量:1122832

I created a win/loss barchart with the y variable, wnls, coded -1 for loss and 1 for win. Then the bars were filled with red/loss and win/green. The code I used is below:

  plot1<-ggplot(data=puck3 %>% 
                mutate(win_loss = ifelse(wnls < 0, "loss", "win")), 
              aes(x=GP, y=wnls, fill = win_loss)) +
  geom_bar(stat="identity", width=0.5)+
  scale_fill_manual(values = c("red", "green")) +
  geom_col() +
  ylim(-5,5)

I now want to expand the data set to include draws as well with loss/draw/win coded -1/0/1. Then the fill colors would be red/yellow/green. How do I alter the code above to do a three-color fill? Thanks for the help.

本文标签: ggplot2How to do a three color fill in R barchartStack Overflow