rggplot2ggpubr

P-value is not calculated and shown in ggplot


Hope you can help me with the following question. First the dataset:

library(ggpubr)
library(tidyverse)

dummy_data <- structure(list(donor_experiment_number = c("NIB920", "NIB916", 
"NIB917", "NIB916", "NIB918", "NIB918", "NIB921", "NIB923", "NIB921", 
"NIB920", "NIB922", "NIB921", "NIB923", "NIB917", "NIB920", "NIB918", 
"NIB922", "NIB917", "NIB916", "CE027", "CE023", "CE030", "CE031", 
"CE034", "CE034", "CE030", "CE033", "CE020", "CE023", "CE025", 
"CE029", "CE024", "CE030", "CE034", "CE020", "CE031", "CE034", 
"CE024", "CE027", "CE023", "CE025", "CE033", "CE033", "CE027", 
"CE029", "CE020", "CE025", "CE029", "CE024", "CE029", "CE031"
), ros_stimulated = c("yes", "yes", "yes", "only cells", "no", 
"yes", "no", "no", "yes", "no", "no", "only cells", "only cells", 
"no", "only cells", "only cells", "only cells", "only cells", 
"no", "no", "no", "no", "yes", "only cells", "TBHP", "only cells", 
"yes", "no", "yes", "yes", "no", "only cells", "yes", "no", "only cells", 
"only cells", "yes", "no", "yes", "only cells", "only cells", 
"no", "only cells", "only cells", "TBHP", "yes", "no", "only cells", 
"yes", "yes", "no"), tissue_origin = c("healthy blood", "healthy blood", 
"healthy blood", "healthy blood", "healthy blood", "healthy blood", 
"healthy blood", "healthy blood", "healthy blood", "healthy blood", 
"healthy blood", "healthy blood", "healthy blood", "healthy blood", 
"healthy blood", "healthy blood", "healthy blood", "healthy blood", 
"healthy blood", "eschar", "eschar", "eschar", "eschar", "eschar", 
"eschar", "eschar", "eschar", "eschar", "eschar", "eschar", "eschar", 
"eschar", "eschar", "eschar", "eschar", "eschar", "eschar", "eschar", 
"eschar", "eschar", "eschar", "eschar", "eschar", "eschar", "eschar", 
"eschar", "eschar", "eschar", "eschar", "eschar", "eschar"), 
    results = c(260.11, 123.35, 132.08, 0.28, 115.46, 119.23, 
    346.64, 129.44, 328.27, 331.88, 145.5, 1.17, 0.53, 79.58, 
    0.53, 0.33, 0.46, 0.3, 88.16, 47.83, 15.99, 20.53, 13.68, 
    0.22, 25.7, 5.36, 27.94, 54.58, 11.52, 40.5, 60.16, 1.69, 
    19.63, 27.16, 0.62, 0.37, 28.75, 14.1, 39.89, 0.19, 0.79, 
    32.8, 0.52, 0.59, 68.86, 45.81, 39.13, 0.75, 11.47, 34.57, 
    12.4)), row.names = c(NA, -51L), class = "data.frame")

When we run a Mann-Whitney test on our data using

compare_means(results ~ tissue_origin, data = filter (dummy_data, ros_stimulated == "yes"), 
              ref.group = "eschar",
              method = "wilcox.test",
              paired = FALSE)

We show that there is a significant difference with a p = 0.00067. So we want to show this in our graph using ggplot

p <- ggplot(data = filter (dummy_data, ros_stimulated == "yes")) +
  aes(x = tissue_origin, y = results, color = donor_experiment_number)+
  geom_point(size = 3, position = 
               position_jitterdodge(dodge.width = 0.5, jitter.width = 0.1)) +
  stat_summary(fun = mean, geom = "crossbar", color = "black", width = 0.3) +
  theme_vsbn() +
          ylim (0, 350) +
          labs(
            title = "",
            y = "MFI",
            x = "Simulation") +
  stat_compare_means (data = filter (dummy_data, ros_stimulated == "yes"),
                      aes(x = tissue_origin, y = results),
                      method = "wilcox.test",
                      paired = FALSE,
                      label = "p.signif",
                      ref.group = "eschar")

plot(p)

R builds the plot, but states that computation failed in stat_compare_means. I cannot see what the problem is in the stat_compare_means function and how I can solve this.

Hope you can help Marcel


Solution

  • You can add the group argument to the mapping in ggplot() and stat_compare_means() to resolve the warning: Warning message: Computation failed in stat_compare_means()

    library(ggpubr)
    
    ggplot(data = filter (dummy_data, ros_stimulated == "yes")) +
      aes(x = tissue_origin, y = results, color = donor_experiment_number, group = tissue_origin)+
      geom_point(size = 3, position = 
                   position_jitterdodge(dodge.width = 0.5, jitter.width = 0.1)) +
      stat_summary(fun = mean, geom = "crossbar", color = "black", width = 0.3) +
      # theme_vsbn() +
      ylim (0, 350) +
      labs(
        title = "",
        y = "MFI",
        x = "Simulation") +
      stat_compare_means (aes(group = tissue_origin),
                          method = "wilcox.test",
                          paired = FALSE,
                          label = "p.signif",
                          ref.group = "eschar")