# NOT RUN {
# T-test
stat.test <- compare_means(
len ~ dose, data = ToothGrowth,
method = "t.test"
)
stat.test
# Create a simple box plot
p <- ggboxplot(ToothGrowth, x = "dose", y = "len")
p
# Perform a t-test between groups
stat.test <- compare_means(
len ~ dose, data = ToothGrowth,
method = "t.test"
)
stat.test
# Add manually p-values from stat.test data
# First specify the y.position of each comparison
stat.test <- stat.test %>%
mutate(y.position = c(29, 35, 39))
p + stat_pvalue_manual(stat.test, label = "p.adj")
# Customize the label with glue expression
# (https://github.com/tidyverse/glue)
p + stat_pvalue_manual(stat.test, label = "p = {p.adj}")
# Grouped bar plots
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
# Comparisons against reference
stat.test <- compare_means(
len ~ dose, data = ToothGrowth, group.by = "supp",
method = "t.test", ref.group = "0.5"
)
stat.test
# Plot
bp <- ggbarplot(ToothGrowth, x = "supp", y = "len",
fill = "dose", palette = "jco",
add = "mean_sd", add.params = list(group = "dose"),
position = position_dodge(0.8))
bp + stat_pvalue_manual(
stat.test, x = "supp", y.position = 33,
label = "p.signif",
position = position_dodge(0.8)
)
# }
Run the code above in your browser using DataLab