1

I am using ggpubr currently to plot my values. Thanks to the facets I managed to create subplots according to some factor. Finally, using the function stat_compare_means() I managed to plot only the differences between groups.

The minimal code to produce my figures is

library(ggpubr)

data("ToothGrowth")

my_comparisons <- list( c("0.5", "1"), c("1", "2"), c("0.5", "2") )

p <- ggboxplot(ToothGrowth, x = "dose", y = "len",
               color = "supp", palette = "npg",
               add = "jitter",
               facet.by = "supp", short.panel.labs = FALSE)
p + stat_compare_means(comparisons = my_comparisons, label = "p.signif")

where supp is the grouping factor, len the outcome and dose the independent variable.

This is the result:

enter image description here

I would like to display also differences within groups (e.g. statistical significance between 0.5|OJ and 0.5|VC), but I think it is not possible with my current code.

Could someone please point me towards some example on how to achieve what I want?

EDIT 2

@Tjebo For clarity purposes I attach here a plot similar to the one I am looking for, where not only the differences between groups (e.g. between red and blue bars), but also within groups (e.g. between two red bars).

I would like (coming back to the minimal reproducible example) to plot as well the p-value between OJ and VC at a dosis of 0.5, for instance.

enter image description here

Luisda
  • 190
  • 13
  • 1
    could we have a [mcve] please ... ? – Ben Bolker Jan 20 '20 at 18:03
  • 1
    @BenBolker Thanks Ben for the interest. I just edited the question so now it has it. – Luisda Jan 20 '20 at 19:11
  • 1
    I am not sure if this helps. But there is a detailed discussion on this topic at: https://github.com/kassambara/ggpubr/issues/65. I haven't seen any examples doing what you want to do though. – Seshadri Jan 20 '20 at 19:21

1 Answers1

0

Statistically, I find this approach fairly questionnable. You are retrospectively creating some subgroups and not adjusting for any confounders that are likely to be present.

But here we go. Just change the x variable and of course the list, which stat_compare_means needs in order to know which groups to compare.

library(ggpubr)

data("ToothGrowth")

my_comparisons <- list( c("OJ", "VC") )

p <- ggboxplot(ToothGrowth, x = "supp", y = "len",
               add = "jitter",
               facet.by = "dose", short.panel.labs = FALSE)
p + stat_compare_means(comparisons = my_comparisons, label = "p.signif")
tjebo
  • 21,977
  • 7
  • 58
  • 94
  • Thanks for the answer. However, that is not what I am looking for. Please have a look at the EDIT 2 where I illustrate the kind of plot I want to obtain – Luisda Jan 21 '20 at 18:13