我已經使用下面的代碼達到了我需要的箱線圖,但我無法提取每個類別中我需要的資訊(Min. - 1st Qu. - Median - Mean - 3rd Qu. - Max.)。我該怎么做?
gapminder %>%
filter(ciclo_real_reg >= 45) %>% ##Removing Outliers
filter(ciclo_real_reg <= 120) %>% ##Removing Outliers
ggplot(aes(x=DxP, y = ciclo_real_reg)) geom_boxplot(aes(color = DxP))
uj5u.com熱心網友回復:
我們可以提取用 繪制繪圖的資料ggplot_build。我mtcars在這個答案中使用來創建一個可重現的示例,因為我不想安裝gapminder.
library(dplyr)
library(ggplot2)
mtcars %>%
ggplot(aes(mpg))
geom_boxplot() ->p
ggplot2::ggplot_build(p)$data[[1]]
結果
xmin xlower xmiddle xupper xmax outliers notchupper
1 10.4 15.425 19.2 22.8 32.4 33.9 21.25989
notchlower y flipped_aes PANEL group xmin_final xmax_final
1 17.14011 0 TRUE 1 -1 10.4 33.9
ymin ymax xid newx new_width weight colour fill size
1 -0.375 0.375 1 0 0.75 1 grey20 white 0.5
alpha shape linetype
1 NA 19 solid
現在,我們感興趣的是xlower, xmiddle,xupper
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/427645.html
上一篇:R:在ggplot2包中使用geom_histogram時,bin的波段是什么?
下一篇:如何在抖動圖中僅繪制一個文本?
