修改我之前的回答
这个问题不是很好,因为 (a) 它没有给出可重现的例子,并且 (b) 它承认使用graphics::boxplot() 的结果来获得答案的可能性。
OP 缺少的是 ggplot2::geom_boxplot 返回一个 ggplot2 图形对象,而不是数据的汇总统计信息。
有关基本图形解决方案,请参阅 help(boxplot) -- boxplot 函数返回您想要的,而不是尝试从 geom_boxplot() 获取。
> bp <- boxplot(mpg~cyl, data=mtcars)
>
> str(bp)
List of 6
$ stats: num [1:5, 1:3] 21.4 22.8 26 30.4 33.9 ...
$ n : num [1:3] 11 7 14
$ conf : num [1:2, 1:3] 22.4 29.6 18.3 21.1 14.3 ...
$ out : num [1:2] 10.4 10.4
$ group: num [1:2] 3 3
$ names: chr [1:3] "4" "6" "8"
stats 组件包含每个组的 5 位数摘要。
> bp$stats
[,1] [,2] [,3]
[1,] 21.4 17.80 13.3
[2,] 22.8 18.65 14.3
[3,] 26.0 19.70 15.2
[4,] 30.4 21.00 16.4
[5,] 33.9 21.40 19.2
>
在ggplot2 中,摘要由stat_boxplot 计算。但是,我不知道如何从结果中提取这些