A ggplot object is a list!
And therefore, we can add more than one component as a list.
geom_mean <- function() {
list(
stat_summary(fun = "mean", geom = "bar", fill = "grey70"),
stat_summary(fun.data = "mean_cl_normal", geom = "errorbar", width = 0.4)
)
}
ggplot(mpg, aes(class, cty)) + geom_mean()