我正在使用 ggplot2 函数 geom_boxplot() 来创建数据的箱线图。
类似于this https://stackoverflow.com/questions/8844845/how-do-i-turn-the-numeric-output-of-boxplot-with-plot-false-into-something-usa问题,我想获取用于创建箱线图的分位数值,例如在矩阵中。
有没有办法打印出 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)