R: changing color of stacked barplot
22,381
ggplot(data=df2, aes(x=dose, y=len, fill=supp)) +
geom_bar(stat="identity")+scale_fill_manual(values = c("Green","tomato"))
Author by
Adrian
Updated on July 09, 2022Comments
-
Adrian almost 2 years
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")
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 acolor = ...
parameter intogeom_bar
but that simply outlines the barplots instead of coloring them in. -
classy_BLINK over 2 yearsI have multiple stacks and I want to change colors too but not manually. Is it possible?