ggplot(data1,aes(x= factor(treat)))+
geom_bar(aes(y = bef_risky), stat = "summary",
fun = "mean", fill = "#00C1D4",
position = position_nudge(x = -0.125, y = 0),
width = 0.25, show.legend = TRUE)+
geom_bar(aes(y = aft_risky), stat = "summary",
fun = "mean", fill = "#FF6666",
position = position_nudge(x = 0.125, y = 0),
width = 0.25, show.legend = TRUE)+
labs(x = "treat", y = "values",
title = "comparison of high risky and low risky")+
scale_x_discrete(labels=c("1" = "Female long",
"2" = " Female short",
"3" = "male long",
"4" = "male short"))
Asked
Active
Viewed 22 times
0

Jilber Urbina
- 58,147
- 10
- 114
- 138
-
2This question needs a [great reproducible example](https://stackoverflow.com/q/5963269/1315767) for better understanding. – Jilber Urbina Jul 27 '21 at 16:37
-
1If you want a legend you have to map on aesthetics, i.e. move `fill = ...` into `aes()` and make use of e.g. `scale_fill_identity(guide = guide_legend())` to get your desired fill colors. – stefan Jul 27 '21 at 16:44