Вам необходимо указать аргумент fill
в geom_boxplot()
, а не в ggplot()
.
Установите последнюю версию dev для rstatix и ggpubr, затем попробуйте следующие коды R.
# Required packages
library(ggpubr) # https://github.com/kassambara/ggpubr
library(rstatix) # https://github.com/kassambara/rstatix
# Stat test
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
stat.test <- ToothGrowth %>%
group_by(dose) %>%
wilcox_test(len~supp, p.adjust.method = 'BH') %>%
mutate(y.position = c(29, 35, 39))
stat.test
# Plot + pvalue
bxp <- ggplot(ToothGrowth, aes(x = dose, y = len)) +
geom_boxplot(aes(fill = supp))
bxp + stat_pvalue_manual(stat.test, x = "dose", label = 'p')
# Add automatically x and y positions
stat.test <- ToothGrowth %>%
group_by(dose) %>%
wilcox_test(len~supp, p.adjust.method = 'BH') %>%
add_xy_position(x = "dose")
bxp + stat_pvalue_manual(stat.test, label = 'p', tip.length = 0)