Understanding ggplot output

Greetings, I want to use the following with my own data but have a couple of questions about the resulting graphs.

dat <- iris

# Edit from here
x <- which(names(dat) == "Species") # name of grouping variable
y <- which(names(dat) == "Sepal.Length" # names of variables to test
| names(dat) == "Sepal.Width"
| names(dat) == "Petal.Length"
| names(dat) == "Petal.Width")
method1 <- "anova" # one of "anova" or "kruskal.test"
method2 <- "t.test" # one of "wilcox.test" or "t.test"
my_comparisons <- list(c("setosa", "versicolor"), c("setosa", "virginica"), c("versicolor", "virginica")) # comparisons for post-hoc tests
# Edit until here


# Edit at your own risk
for (i in y) {
  for (j in x) {
    p <- ggboxplot(dat,
      x = colnames(dat[j]), y = colnames(dat[i]),
      color = colnames(dat[j]),
      legend = "none",
      palette = "npg",
      add = "jitter"
    )
    print(
      p + stat_compare_means(aes(label = paste0(..method.., ", p-value = ", ..p.format.., " (", ifelse(..p.adj.. > 0.05, "not significant", ..p.signif..), ")")),
        method = method1, label.y = max(dat[, i], na.rm = TRUE)
      )
      + stat_compare_means(comparisons = my_comparisons, method = method2, label = "p.format") # remove if p-value of ANOVA or Kruskal-Wallis test >= 0.05
    )
  }
}

Questions

  • In the first graph, is the top value shown "1.9e-07" a p-value?
    • If so, why isn't it written out as such?
    • If son, is it considered significant?
    • If so, why aren't asterisks shown?
  • The second and third numbers are p-values
    • Are they significant?
    • If so, why aren't asterisks shown?
  • What level of significance do the 4 asterisks shown represent?
  • Could a graph have comparisons with p-values at different levels of significance (e.g., 0.05, 0.01, 0.001 etc.)?

Any help interpreting these graphs would be very helpful. Thank you.
Jason

#rstatsnewbie :slightly_smiling_face:

p.s. the original code was found here:
Communicating ANOVA results a better way

I think your actual questions are about the annotation that results from using ggpubr (which is a package that extends the use of ggplot2, but isn't ggplot2 itself). It looks like the author of the post you're referring to has DISQUS on their site (where the original post is), and is actively discussing. So, you might try asking your questions over there, since he'll know the rationale behind the graphics!

1 Like

Thanks I appreciate the information about ggpubr and the ability to comment on his blog. I only saw that "comments we closed" at the bottom of the page and didn’t think to look elsewhere. Thus, for now, I guess you’ve 'solved' my problem. :thinking::+1:

Cheers,
Jason, the #rstatsnewbie :wink:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.