ggplot2: Add p-value to grouped box plots

后端 未结 1 979
慢半拍i
慢半拍i 2021-01-25 14:23

I am trying to add p_values to my graph using \"stat_signif\" function.
The problem is that my boxplots are grouped box plots where I want to compare every 2 box plots of th

相关标签:
1条回答
  • 2021-01-25 15:08

    You haven't posted enough data to get p-values, so I'm posting an example that you can adjust to your dataset:

    library(tidyverse)
    library(ggpubr)
    
    mtcars %>%
      mutate_at(vars(am, cyl), as.factor) %>%
      ggplot(aes(cyl, disp, fill=am))+
      geom_boxplot()+
      stat_compare_means(aes(group = am))
    

    You can usestat_compare_means(aes(group = am), label = "p.format") if you want to have only the p values in your plot.

    0 讨论(0)
提交回复
热议问题