Hi,
I need to place medians and means on one boxplot and annotate it:
means <- aggregate(weight ~ group, PlantGrowth, mean)
medians <- aggregate(weight ~ group, PlantGrowth, median)
PlantGrowth |>
summarize(ymin = quantile(weight, 0),
lower = quantile(weight, 0.25),
median = median(weight),
mean = mean(weight),
upper = quantile(weight, 0.75),
ymax = quantile(weight, 1)) %>%
ggplot(aes(x=group, y=weight, fill=group)) + geom_boxplot(stat = 'identity', aes(ymin = ymin, lower = lower, middle = mean, upper = upper,
ymax = ymax)) +
stat_summary(fun=mean, colour="darkred", geom="line",
shape=18, size=3, show.legend=FALSE) +
geom_text(data = means, aes(label = weight, y = weight + 0.08))+
geom_text(data = medians, aes(label = weight, y = weight + 0.08))
but it throws an error:
Error in FUN(X[[i]], ...) : object 'group' not found
What do I do wrong ?