kassambara / rstatix

Pipe-friendly Framework for Basic Statistical Tests in R
https://rpkgs.datanovia.com/rstatix/
432 stars 51 forks source link

How to plot manual p values with x axis as group variable without using facet feature #176

Open ShixiangWang opened 1 year ago

ShixiangWang commented 1 year ago
df <- ToothGrowth
df$dose <- as.factor(df$dose)
df

# Statistical test
stat.test <- df %>%
  group_by(dose) %>%
  t_test(len ~ supp) %>%
  adjust_pvalue() %>%
  add_significance("p.adj")
stat.test

# Visualization
ggboxplot(
  df, x = "dose", y = "len",
  color = "supp", fill = "supp", palette = "jco",
  ylim = c(0, 40)
)

ggboxplot(
  df, x = "dose", y = "len",
  color = "supp", fill = "supp", palette = "jco",
  ylim = c(0, 40)
) + stat_pvalue_manual(stat.test, label = "p.adj", y.position = 35)

image

image