I want to create some box plots and add the mean, median and n above them. For that I followed someones code. first the function:
box.stats_weight<- function(y, upper_limit = max(mean_weight) * 1.15) {
return(data.frame(
y = 0.95 * upper_limit,
label = paste(
"n =", length(y), "\n",
"mean =", round(mean(y), 2), "\n",
"median =", round(median(y), 2), "\n"
)
))
}
I get no errors running that code. When I try to implement it in my Boxplot it get the Error :
Error during wrapup: argument "y" is missing, with no default
My Boxplot code looks like the following:
weight_box <- ggboxplot(SB01.data, x = "treatment", y = "mean_weight",
add = "jitter", shape = "treatment"+
stat_summary(fun.data = box.stats_weight(), geom = "text", hjust = 0.5, vjust = 0.9) +
theme_classic())