r - ggplot2 show separate mean values in box plot for grouped data -
i create box plot grouped data shows mean of each group point in box. using following code, single point 2 groups.
df <- data.frame(a=factor(rbinom(100, 1, 0.45), label=c("m","w")), b=factor(rbinom(100, 1, 0.3), label=c("young","old")), c=rnorm(100)) ggplot(aes(y = c, x = b, fill = a), data = df) + geom_boxplot() + stat_summary(fun.y="mean", geom="point", shape=21, size=5, fill="white")
part of problem changing fill of point, since fill property determines 2 box plots of different color should drawn, point behaves if there 1 group again. think should give want.
ggplot(df, aes(x=b, y=c, fill=a)) + geom_boxplot() + stat_summary(fun.y="mean", geom="point", size=5, position=position_dodge(width=0.75), color="white")
Comments
Post a Comment