7
library(ggplot2)
df2 <- data.frame(supp=rep(c("VC", "OJ"), each=3),
                dose=rep(c("D0.5", "D1", "D2"),2),
                len=c(6.8, 15, 33, 4.2, 10, 29.5))
head(df2)
ggplot(data=df2, aes(x=dose, y=len, fill=supp)) +
  geom_bar(stat="identity")

enter image description here

I have a simple stacked barplot, and I would like to change the colors manually. More specifically, I would like to flip the colors used for fill = supp (i.e. teal for OJ instead). I've trid adding a color = ... parameter into geom_bar but that simply outlines the barplots instead of coloring them in.

Adrian
  • 9,229
  • 24
  • 74
  • 132
  • 3
    You want to add `+ scale_fill_manual(values = c("green", "violet"))` to the end of your code as shown to add your own colors (notice this is **FILL**, not **COLOR**). However, to keep those fill colors and just flip them, use `+ scale_fill_hue(direction = -1)`. – Brian May 01 '17 at 15:39

1 Answers1

14
ggplot(data=df2, aes(x=dose, y=len, fill=supp)) +
  geom_bar(stat="identity")+scale_fill_manual(values = c("Green","tomato"))

green and tomato colours added

sai saran
  • 737
  • 9
  • 32