kassambara / rstatix

Pipe-friendly Framework for Basic Statistical Tests in R
https://rpkgs.datanovia.com/rstatix/
440 stars 50 forks source link

xmin/xmax from add_xy_position when x labels do not match between facets #203

Open cpverschoor opened 6 months ago

cpverschoor commented 6 months ago

Hi,

I am having trouble with the alignment of p-values and bars across facets when the x labels are not the same and scales are "free". Looks like add_xy_position is ignoring the "group" argument, although I might be misunderstanding the setup.

Below is a reproduceable example.

Many thanks! Chris


library(ggplot2)
library(rstatix)
df <- data.frame(y=c(1,2,3,4,5,6,7,8,9,10),
                 x=c("a","a","b","b","c","c","d","d","e","e"),
                 group=c("X","X","X","X","Y","Y","Y","Y","Y","Y")
                 )
stat.test <- t_test(group_by(df,group),y~x)
  stat.test <- add_xy_position(stat.test,x="x",group="group",scales="free")

ggplot(df,aes(x=x,y=y))+
  ggplot2::geom_point()+
  facet_grid(~group,scales="free")+
  stat_pvalue_manual(stat.test,label="{p}")

image