r - 从geom_boxplot()获取分位数值

标签 r ggplot2 boxplot

我正在使用ggplot2函数geom_boxplot()创建数据的箱形图。

this问题类似,我想获取用于创建箱线图的分位数,例如在矩阵中。
有没有办法打印出geom_boxplot()中使用的值?

最佳答案

可能最简单的方法是使用ggplot聚合的外部,但是这是在创建的图上使用ggplot函数使用ggplot_build的方法:

library(ggplot2)
p <- ggplot(mtcars, aes(x=factor(gear), y=mpg)) + geom_boxplot() 
ggplot_build(p)$data

[[1]]
  ymin lower middle  upper ymax outliers notchupper notchlower x PANEL group weight ymin_final ymax_final
1 10.4  14.5   15.5 18.400 21.5            17.09102   13.90898 1     1     1      1       10.4       21.5
2 17.8  21.0   22.8 28.075 33.9            26.02695   19.57305 2     1     2      1       17.8       33.9
3 15.0  15.8   19.7 26.000 30.4            26.90729   12.49271 3     1     3      1       15.0       30.4
   xmin  xmax
1 0.625 1.375
2 1.625 2.375
3 2.625 3.375

关于r - 从geom_boxplot()获取分位数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34977882/

相关文章:

r - 如何有效地合并两个数据集?

r - ggplot : Manually add legends for aesthetics that are not mapped

r - 使用 ggplot2 绘制自举样本(多列)

r - ggplot2 在彩色线条之上添加彩色形状并将两者组合成一个图例

python - Python 中调整后的箱线图

r - 在 R 中为同一张表中的两列并排绘制箱线图

r - 检查包是否在 R 中正确安装

r - 排序或过滤与处理

r - 如何根据多列字符串中的字符复制行

r - 使用 ggplot2 的表格箱线图