Edit of my previous answer
This question isn't well-posed, because (a) it doesn't give a reproducible example and (b) it admits the possibility of using the result of graphics::boxplot()
to get an answer.
What the OP is missing is that ggplot2::geom_boxplot
returns a ggplot2 graphics object, not the summary statistics for the data.
For the base graphics solution, see help(boxplot)
-- the boxplot
function returns what you want, rather than trying to get this from 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"
The stats
component contains the 5-number summary for each group.
> 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
>
In ggplot2
the summaries are calculated by stat_boxplot
. However, I know of no way to extract these from the result