从geom_boxplot()获取分位数值 [英] Get Quantile values from geom_boxplot()
本文介绍了从geom_boxplot()获取分位数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用ggplot2函数geom_boxplot()来创建我的数据盒形图。
类似于有没有办法打印geom_boxplot()中使用的值?可能最简单的方法是使用 ggplot
聚合的外部,但是这里是用 ggplot
使用函数 ggplot_build
在创建的图上:
library(ggplot2)
p < - ggplot (mtcars,aes(x = factor(齿轮),y = mpg))+ geom_boxplot()
ggplot_build(p)$ data
[[1]]
ymin lower中间上限ymax异常值上限上限下限x PANEL组重量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
I'm using ggplot2 function geom_boxplot() to create boxplots of my data.
Similarly to this question, I'd like to get the quantile values used for the creation of the boxplot, e.g., in a matrix. Is there a way to print out the values used within geom_boxplot()?
解决方案
Probably the easiest way is to use an outside of ggplot
aggregate, but here's how to do it with ggplot
, using the function ggplot_build
on a created plot:
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
这篇关于从geom_boxplot()获取分位数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文