0

I am a total beginner in R and I was wondering if I could get some help in data visualisation using ggplot2 package.

I am trying to mark significance level with adjusted p-value (with Bonferroni correction) instead of normal p-value with asterisk.

The codes I tried are...

stat_compare_means(aes(label=..p.adj.., group=sample_type), label = "p.signif", method = "t.test", hide.ns = TRUE)

stat_compare_means(aes(group=sample_type), p.adjust.method = "bonferroni", label = "p.signif", method = "t.test", hide.ns = TRUE)
Jaap
  • 81,064
  • 34
  • 182
  • 193
Kim So Yon
  • 85
  • 7
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Mar 06 '20 at 16:05

1 Answers1

1

See the EnvStats package for this. The example provided by the authors (p. 1180) is:

library(ggplot2)
library(EnvStats)
p <- ggplot(mtcars, aes(x = factor(cyl), y = mpg, color =     
factor(cyl))) + theme(legend.position = "none")

dev.new()
p + geom_point() +
stat_n_text() + stat_mean_sd_text() +
stat_test_text() +
labs(x = "Number of Cylinders", y = "Miles per Gallon")
Ben
  • 1,113
  • 10
  • 26