如何从 t 检验创建箱线图

How to create a boxplot from t -test

这是我已有的代码和数据:

library(tidyverse)
t.test(BMIS ~ CONDITION, var.equal =TRUE, data = BMIS_DATA)
descriptive_statistics = BMIS_DATA %>% 
                           group_by(CONDITION) %>% 
                           summarise(
                             mean = mean (BMIS), 
                             sd = sd (BMIS),  
                             n = n ()
                         )
view(descriptive_statistics)
mean_difference = descriptive_statistics [1,2] - descriptive_statistics [2,2]

这给了我:

Two Sample t-test

data:  BMIS by CONDITION
t = 3.7455, df = 44, p-value = 0.0005201
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
  4.299781 14.317362
sample estimates:
mean in group HAPPY   mean in group SAD 
           45.88000            36.57143 

如何从中创建一些视觉数据?

如果我正确理解了你的问题,你可以很容易地根据你的 CONDITION 变量表示分布。 以下代码允许您从箱线图中看到这一点:

library(ggplot2)
ggplot(BMIS_DATA,aes(x=CONDITION,y=BMIS,col=CONDITION))+geom_boxplot()

然后就可以应用ggplot2包的经典函数了。自定义:?geom_boxplot.