How to make boxplot with pairwise and overall p value from Limma
0
0
Entering edit mode
Chris ▴ 20
@3fdb6f97
Last seen 3 months ago
United States

Hi all,

I use limma to compare pathway score between 3 groups. Then I would like to make boxplot with overall p value and pairwise p value. I use this with method ='t.test' or method='anova':

ggboxplot(data, x = "disease_state", y = "pathway_name",
          color = "dem8", palette = "jco") + 
  stat_compare_means(comparisons = my_comparisons, method = 't.test') + # Add pairwise comparisons p-value
  stat_compare_means(label.y = 0.6, method = 't.test') +
  labs(y = "Pathway Score", title = "pathway_name")

http://www.sthda.com/english/articles/24-ggpubr-publication-ready-plots/76-add-p-values-and-significance-levels-to-ggplots/

The value from t test or anova is different from the p value from limma:

topTable <- topTable(fit2, number=Inf, sort.by="none")
topTableLSvsNC <- topTable(fit2, coef="LSvsNC", number=Inf, sort.by="none")

Would you please have an explanation for the difference and how to make boxplot with overall p value and pairwise p value from limma? Is that because statistical model difference which limma is better? I use a manual way: extract p value from topTable and then use geom_text to annotate to boxplot. But for pairwise p value I don't know how. Thank you so much!

enter image description here

t.test boxplot limma anova • 1.8k views
ADD COMMENT
1
Entering edit mode

Regarding the difference between the p-value from a t-test and a p-value from limma, this has been previously discussed in this forum, at least in this post.

ADD REPLY
0
Entering edit mode

Thanks Robert. I think p value from limma is better, now just try to add them to boxplot.

ADD REPLY
0
Entering edit mode

Read LIMMA: where to find the ANOVA?

topTable(fit2) table reports the ANOVA p-value.

topTableLSvsNC reports the p-value for the specified contrast. Loop over the contrasts to get the "pairwise" p-values. These p-values are adjusted per contrast.

ADD REPLY
0
Entering edit mode

Yes, I know how to extract these p value but how to add them to the boxplot in a nice way like the example plot above?

ADD REPLY
1
Entering edit mode

ggpubr is based on ggsignif. Read the documentation of geom_signif.

All you need is the list of comparisons and the corresponding text to place on top of the horizontal bar.

Here is a simple example using that helps you building this.

library(ggplot2)
library(ggsignif)
ggplot(mpg, aes(class, hwy)) +
    geom_boxplot() +
    geom_signif(
        annotations = c("**", "***"),
        comparisons = list(c("2seater", "compact"), c("midsize", "minivan"))
    )

custom aanotations

ADD REPLY
0
Entering edit mode

Thank you so much! I try now, hope it works. It worked. I try to figure out how to make a boxplot and then try to combine 11 boxplots into one figure. For only one overall p value, this worked:

long_data <- merge(long_data, p_values_df, by = "Pathway")
ggplot(long_data, aes(x = dem8, y = Score, fill = dem8)) +
  geom_boxplot() +
  facet_wrap(~ Pathway, scales = "free_y", ncol = 4) +  # Adjust scales and ncol as needed
  labs(title = "", x = "Disease state", y = "Pathway Score") +
  theme_light() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1),  # Rotate x-axis text for readability
        strip.text.x = element_text(size = 10)) +  # Adjust size of facet labels if needed
  geom_text(aes(x = Inf, y = Inf, label = annotation_text),
            hjust = 1.1, vjust = 2, size = 4, colour = "red", inherit.aes = FALSE)

I used pivot_longer() to make long_data. This way, I don't have to manually annotate each plot. Do you have any suggestion for pairwise p value for multiple boxplot?

ADD REPLY

Login before adding your answer.

Traffic: 656 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6