Search code examples
rdata-visualizationboxplott-test

How to create a boxplot from t -test


this is the code and data i already have:

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]

which gave me :

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 

How do I create some visual data from this?


Solution

  • If I understood your question correctly, you can easily represent the distributions according to your CONDITION variable. The following code allows you to visualize this from boxplots:

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

    Then, the classical functions of the ggplot2 package can be applied. To customize : ?geom_boxplot.