箱线图均值的精确值

exact value of the mean of a boxplot

我生成了一个包含三个变量("Jahreszeit"、"Fracht"、"Bewirtschaftungsform")的 boxplot,如下所示:

ggplot(daten,aes(x=Jahreszeit, y=Fracht))+ geom_boxplot() +
     facet_wrap(~ Bewirtschaftungsform)+ 
geom_point(position = position_jitter(width = 0.1))+
     stat_summary(fun.data=f, geom="text", vjust=+1.5, col="black")

我的问题是,是否有办法提取因子每个类别的均值的准确值?

我会使用 aggregateplyr 来完成这样的任务。使用聚合,您可以通过以下调用获得组均值(我假设是 Fracht):

groupMeans <- aggregate(Fracht ~ Bewirtschaftungsform, daten, mean)

打印时建议四舍五入:

groupMeans$Fracht <- round(groupMeans$Fracht, 2)

在 ggplot 对象中,您可以添加:

+ geom_text(data=groupMeans,aes(label=price,y=0,x=0))

最后一项可能需要对 x 和 y 值进行一些调整以优化位置。