You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I want to plot the stats results for only the significant results from a stats test I can filter the output tibble before running add_xy_position, however this results in the y positions being spaced inconsistently rather than all the brackets being evenly separated.
For example from the following data:
library(tidyverse)
library(rstatix)
library(ggpubr)
set.seed(1)
tibble(
A = rnorm(10,mean=1),
B = rnorm(10,mean=1),
c = rnorm(10,mean=3),
D = rnorm(10,mean=5),
E = rnorm(10,mean=1)
) %>%
pivot_longer(
cols=everything(),
names_to="group",
values_to="value"
) %>%
filter(!is.na(group)) -> data
If I do a test on all groups and calculate the y position all values are equally spaced:
data %>%
tukey_hsd(value~group) %>%
add_xy_position() -> stats_all
# All the differences are the same
diff(stats_all$y.position, lag=1)
# Gives [1] 0.4788 0.4788 0.4788 0.4788 0.4788 0.4788 0.4788 0.4788 0.4788
...and the plot shows equal spacing:
data %>%
ggplot(aes(x=group, y=value)) +
geom_boxplot() +
stat_pvalue_manual(stats_all)
However if I filter for only significant results then I get unequal spacing:
data %>%
tukey_hsd(value~group) %>%
filter(p.adj<0.05) %>%
add_xy_position() -> stats_significant
# Spacings are now different between different comparisons
# Space is left for other comparisons even though they're
# not there
diff(stats2$y.position, lag=1)
# Gives [1] 0.4788 0.9576 0.4788 0.9576 0.4788 0.4788
..the plot is therefore also unequal
data %>%
ggplot(aes(x=group, y=value)) +
geom_boxplot() +
stat_pvalue_manual(stats_significant)
I should also note that the same effect exists if you use the hide.ns option to stat_pvalue_manual but this is likely a different issue with a different fix.
The text was updated successfully, but these errors were encountered:
Hi,
I got the same issue that is due to the fact that filtering occurs after positions have been computed.
My current workaround is to explicitly set the comparisons.
If I want to plot the stats results for only the significant results from a stats test I can filter the output tibble before running
add_xy_position
, however this results in the y positions being spaced inconsistently rather than all the brackets being evenly separated.For example from the following data:
If I do a test on all groups and calculate the y position all values are equally spaced:
...and the plot shows equal spacing:
However if I filter for only significant results then I get unequal spacing:
..the plot is therefore also unequal
I should also note that the same effect exists if you use the
hide.ns
option tostat_pvalue_manual
but this is likely a different issue with a different fix.The text was updated successfully, but these errors were encountered: