kassambara / ggpubr

'ggplot2' Based Publication Ready Plots
https://rpkgs.datanovia.com/ggpubr/
1.14k stars 165 forks source link

Error adding p-value (group comparisons) to ggboxplot #46

Closed jmicrobe closed 2 years ago

jmicrobe commented 7 years ago

Great package! I'm trying to apply it to a relatively small data set that I have and I'm getting an error when trying to add significance data to the plot.

Running

compare_means(per_bead ~ beads, protein)

yields a 6 x 8 tibble with some of the significance data I'm hoping to add to my plot:

# A tibble: 6 x 8
       .y. group1 group2          p     p.adj p.format p.signif   method
     <chr>  <chr>  <chr>      <dbl>     <dbl>    <chr>    <chr>    <chr>
1 per_bead     20     10 1.00000000 1.0000000    1.000       ns Wilcoxon
2 per_bead     20      8 0.30649217 0.9194765    0.306       ns Wilcoxon
3 per_bead     20      5 0.03038282 0.1822969    0.030        * Wilcoxon
4 per_bead     10      8 0.56136321 1.0000000    0.561       ns Wilcoxon
5 per_bead     10      5 0.06060197 0.3030098    0.061       ns Wilcoxon
6 per_bead      8      5 0.06060197 0.3030098    0.061       ns Wilcoxon

Following the example given in the docs for adding p-values comparing groups:

my_comparisons <- list(c("5, 20"), c("5, 10"), c("10, 20"))
ggboxplot(prot, x = "beads", y = "per_bead",
          color = "beads", palette = "jco") +
  stat_compare_means(comparisons = my_comparisons)

I get the following errors:

Warning messages:
1: Removed 16 rows containing non-finite values (stat_boxplot). 
2: Removed 16 rows containing non-finite values (stat_signif). 
3: Computation failed in `stat_signif()`:
missing value where TRUE/FALSE needed

I've tried several different arguments in stat_compare_means() without success. I'm hoping to achieve something similar to the example plot below (or just the output of "p.signif" instead of a value):

image

kassambara commented 7 years ago

Hi,

Use:

my_comparisons <- list(c("5", "20"), c("5", "10"), c("10", "20"))

instead of:

my_comparisons <- list(c("5, 20"), c("5, 10"), c("10, 20"))
jmicrobe commented 7 years ago

@kassambara of course it was a simple typo. That worked great, thank you. Can't wait to use this package more!

beadsprotsig

elcansaito commented 6 years ago

This is my data

ID Period Tra
2 O 33.81648475
4 O 46.0599032
7 O 39.24617467
15 O 34.30622148
21 O 42.71691764
23 O 38.99065985
24 O 48.87056621
51 O 41.14124291
55 O 39.86366882
57 O 34.41268599
72 I 40.86443519
93 I 40.01271913
94 I 38.52221601
97 I 40.60892037
128 I 34.41268599
129 I 36.41421875
141 I 39.73591141
148 I 37.64920704
151 I 34.90242273
166 I 39.13971016
179 M 45.46370195
180 M 40.43857716
181 M 49.55193907
183 M 44.05837044
184 M 47.89109274
185 M 46.37929672
188 M 51.10632089
189 M 36.52068326
198 M 45.37853034
200 M 41.52451514

I am trying to add the pvalues on a boxplot and I always get the same error. I have tried different methods but I always get the same error.

METHOD 1

my_comparisons <- list( c("O M"), c("O I"), c("I M") ) ggboxplot(newdata, x = "Period", y = "tra", color = "Period", palette = "jco",add="jitter")+ stat_compare_means(comparisons = my_comparisons,method = "anova")+ # Add global p-value stat_compare_means(aes(label = ..p.signif..), method = "t.test", ref.group = "0.5")

METHOD 2

ggboxplot(newdata, x = "Period", y = "tra", color = "Period", palette = "npg")+ stat_compare_means(method = "anova", label.y = 50)+ # Add global p-value stat_compare_means(aes(label = ..p.signif..), method = "t.test", ref.group = "0.5")

ALWAYS THE SAME ERROR and I don´t see the starts or the pvalues on the plot 2: Computation failed in stat_compare_means(): missing value where TRUE/FALSE needed

Any suggestions?

THANKS,

bioemprendiendo commented 5 years ago

How to add comparissons between treatments for heach gene expression? i mean, a want to add p-value and brackets for each gene (GATA3, PTEN, XBP1) but comparing BRCA to OV and BRCA to LUSC for each gene like this:

my_comparisons <- list(c("BRCA", "OV"), c("OV", "LUSC")) ggboxplot(expr, x = "dataset", y = "GATA3", title = "GATA3", ylab = "Expression", color = "dataset", palette = "jco")+ stat_compare_means(comparisons = my_comparisons)

image

but doing this:

ggboxplot(expr, x = "dataset", y = c("GATA3", "PTEN", "XBP1"), merge = "flip", ylab = "Expression", palette = "jco")

image

thank you

micdonato commented 3 years ago

Why is this closed? I was interested in the same, and I cannot get it to work

NJU-Bio-Info commented 2 years ago

same question......

kassambara commented 2 years ago

Are you looking for something like this:

library(ggpubr)

bxp <- ggboxplot(gene_expression, x = "dataset",
          y = c("GATA3", "PTEN", "XBP1"),
          merge = "flip",
          ylab = "Expression",
          palette = "jco")
bxp +
  geom_pwc(
    aes(group = dataset), tip.length = 0,
    method = "wilcox_test", label = "p.adj.format",
    bracket.nudge.y = -0.08
  ) +
  scale_y_continuous(expand = expansion(mult = c(0, 0.1)))

The following docs might help:

Please, consider installing the latest dev version of ggpubr using devtools::install_github("kassambara/ggpubr")