I have a data frame for two groups and 9 variables
> head(aa)
treatment variable value
1 pre Sig1 0.1173863
2 pre Sig1 0.1888243
3 pre Sig1 0.2191765
4 pre Sig1 0.1277735
5 pre Sig1 0.1711712
6 pre Sig1 0.0000000
> class(aa)
[1] "data.frame"
> str(aa)
'data.frame': 1026 obs. of 3 variables:
$ treatment: Factor w/ 2 levels "post","pre": 2 2 2 2 2 2 2 2 2 2 ...
$ variable : Factor w/ 9 levels "Sig1","Sig2",..: 1 1 1 1 1 1 1 1 1 1 ...
$ value : num 0.117 0.189 0.219 0.128 0.171 ...
> tail(aa)
treatment variable value
1021 post Sig9 0
1022 post Sig9 0
1023 post Sig9 0
1024 post Sig9 0
1025 post Sig9 0
1026 post Sig9 0
>
I am using this code
library(ggpubr)
> p <- ggboxplot(aa, x = "variable", y = "value",color = "treatment")
> my_comparisons <- c("pre","post")
> p + stat_compare_means(comparisons = my_comparisons)+ stat_compare_means(label.y = 50)
Warning message:
Computation failed in `stat_signif()`:
missing value where TRUE/FALSE needed
>
But I am getting this weird plot
While something like this is my goal
I really don't know where I am doing wrong
I used ggplot where I got something like this but I need statistics that is why I have stuck on this
I then used this code
> DF <- aa %>% pivot_longer(.,cols = c(Sig1,Sig2,Sig3, Sig4,Sig5,Sig6,Sig7,Sig8,Sig9), names_to = "var", values_to = "val")
> View(DF)
> library(ggplot2)
> library(ggpubr)
> ggplot(DF, aes(x = treatment, y = val, fill = treatment))+
+ geom_boxplot()+
+ stat_compare_means(comparisons = c("pre","post")+
+ stat_compare_means()+
+ facet_grid(var~., scales = "free")
+
But I got another weird plot
But changing the scale I got this but gives one statistics
While I need one stat for each variable between pre and post groups
This solution gives to statistics
> p <- ggboxplot(aa, x = "variable", y = "value",color = "treatment",facet.by = "variable")
> p + stat_compare_means(comparisons = my_comparisons)+ stat_compare_means(label.y =2)
When I edited my code
> p <- ggboxplot(aa, x = "variable", y = "value",color = "treatment")
> p + stat_compare_means(aes(group = variable))
>
But again one stat