Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capital letter NS. remaining after hide.ns in ggplot with ggpubr stat_compare_means #171

Closed
natjoh opened this issue Apr 5, 2019 · 6 comments

Comments

@natjoh
Copy link

natjoh commented Apr 5, 2019

I want to hide.ns in a ggplot after stat_compare_means is added, it hides all but one random capital letter NS.
install.packages("tidyverse")
library(tidyverse)
library(ggpubr)

dat2<-data.frame(R_Full_simple)
R_Full_simple

#ggplot build
dat2$grp.fac <- factor(dat2$spacer_type,levels=c("1","2","0","3","4"),
labels = c("a) non-valved \n spacer", "b) valved \n spacer",
"c) direct", "d) adapter", "e) syringe") )
dat2$grp.size <- factor(dat2$ett_size,levels=c("1","2","3","4"),
labels = c("3 mm", "5 mm", "7 mm", "9 mm"))

ett <- ggplot(dat2, outlier.shape = NA, mapping = aes(x = grp.fac, y = ett_pct, fill = grp.fac))+
facet_wrap(~grp.size, scales = "free_y")+
geom_boxplot()+geom_point()+theme_classic()
ett
#compare within group
ett+stat_compare_means(comparisons = list(c("c) direct", "a) non-valved \n spacer"),
c("a) non-valved \n spacer", "b) valved \n spacer"),
c("b) valved \n spacer", "d) adapter"), c("b) valved \n spacer",
"e) syringe"),
c("d) adapter", "e) syringe"), c("c) direct", "b) valved \n spacer"),
c("c) direct", "d) adapter"), c("c) direct", "e) syringe"),
c("a) non-valved \n spacer", "e) syringe"), c("a) non-valved \n spacer",
"d) adapter")),
label = "p.signif", hide.ns = TRUE)+
stat_compare_means(method = "anova",label.y = -2)

R_Full_simple.xlsx
Rplot

@Sergei-EMC
Copy link

Hi natjoh,

I'm struggling with the same problem and have searched everywhere for a solution but unfortunately found nothing. Did you come up with a solution to this problem? Thanks in advance

Sergei

@kassambara
Copy link
Owner

Would you please provide your session info? I can't reproduce this issue with current dev version of ggpubr.

library("ggpubr")
comparisons <- list(c("ctrl", "trt1"), c("ctrl", "trt2"), c("trt1", "trt2"))
ggboxplot(PlantGrowth, x = "group", y = "weight") +
  stat_compare_means(comparisons = comparisons, label = "p.signif")

Rplot

Hide ns:

comparisons <- list(c("ctrl", "trt1"), c("ctrl", "trt2"), c("trt1", "trt2"))
ggboxplot(PlantGrowth, x = "group", y = "weight") +
  stat_compare_means(comparisons = comparisons, label = "p.signif", hide.ns = TRUE)

Rplot18

Anyway, the option hide.ns avoids printing "NS" for non-significant comparisons, but this won't prevent the lines from being drawn.

An alternative solution would be to go as follow:

library(rstatix) # devtools::install("kassambara/rstatix")
library(ggpubr) # devtools::install("kassambara/ggpubr")
stat.test <- PlantGrowth %>% 
  t_test(weight ~ group) %>%
  add_xy_position()
ggboxplot(PlantGrowth, x = "group", y = "weight") +
  stat_pvalue_manual(stat.test, hide.ns = TRUE)

Rplot19

stat.test
# A tibble: 3 x 12
  .y.    group1 group2 statistic    df       p  p.adj p.adj.signif y.position groups     xmin  xmax
  <chr>  <chr>  <chr>      <dbl> <dbl>   <dbl>  <dbl> <chr>             <dbl> <list>    <int> <int>
1 weight ctrl   trt1        1.19  16.5 0.25    0.25   ns                 6.34 <chr [2]>     1     2
2 weight ctrl   trt2       -2.13  16.8 0.0479  0.0958 ns                 6.39 <chr [2]>     1     3
3 weight trt1   trt2       -3.01  14.1 0.00930 0.0279 *                  6.44 <chr [2]>     2     3

@Sergei-EMC
Copy link

Hi,

Thank you for your reply! I'm on R version 3.4.1 (2017-06-30), ggpubr_0.2.1 .

If I run this code:

G8 <-ggplot(CC10,aes(x=variable, y=value)) +stat_boxplot(geom = "errorbar", width = 0.25,linetype=1)+ geom_boxplot(fill=c("turquoise4","lightcoral", "steelblue1"),outlier.shape = 1)+scale_fill_brewer(palette="Set1")+ theme_classic()+ scale_x_discrete(breaks=c("H_score_CC10_normal", "H_score_CC10_CPAM", "H_score_CC10_MP"), labels=c("Normal" ,"CPAM", "MP"))+ theme(axis.title.x = element_blank(),axis.title.y = element_blank())+ stat_compare_means(comparisons = list(c("H_score_CC10_normal","H_score_CC10_CPAM"),c("H_score_CC10_CPAM","H_score_CC10_MP"), c("H_score_CC10_normal","H_score_CC10_MP")),paired=TRUE, method="wilcox.test", label="p.signif", hide.ns=TRUE, symnum.args= list(cutpoints = c(0, 0.017, 1), symbols = c("*", "ns")), label.y = c(320,335,350),tip.length=0.02)

I get
image
`
It shows the capital letters "NS." whereas in other plots it returns the small letter "ns" I specified.
I don't understand why this is happening and how I can fix this.

Thanks!

@schlaipferm
Copy link

schlaipferm commented Jan 23, 2020

I want to hide.ns in a ggplot after stat_compare_means is added, it hides all but one random capital letter NS.
install.packages("tidyverse")
library(tidyverse)
library(ggpubr)

dat2<-data.frame(R_Full_simple)
R_Full_simple

#ggplot build
dat2$grp.fac <- factor(dat2$spacer_type,levels=c("1","2","0","3","4"),
labels = c("a) non-valved \n spacer", "b) valved \n spacer",
"c) direct", "d) adapter", "e) syringe") )
dat2$grp.size <- factor(dat2$ett_size,levels=c("1","2","3","4"),
labels = c("3 mm", "5 mm", "7 mm", "9 mm"))

ett <- ggplot(dat2, outlier.shape = NA, mapping = aes(x = grp.fac, y = ett_pct, fill = grp.fac))+
facet_wrap(~grp.size, scales = "free_y")+
geom_boxplot()+geom_point()+theme_classic()
ett
#compare within group
ett+stat_compare_means(comparisons = list(c("c) direct", "a) non-valved \n spacer"),
c("a) non-valved \n spacer", "b) valved \n spacer"),
c("b) valved \n spacer", "d) adapter"), c("b) valved \n spacer",
"e) syringe"),
c("d) adapter", "e) syringe"), c("c) direct", "b) valved \n spacer"),
c("c) direct", "d) adapter"), c("c) direct", "e) syringe"),
c("a) non-valved \n spacer", "e) syringe"), c("a) non-valved \n spacer",
"d) adapter")),
label = "p.signif", hide.ns = TRUE)+
stat_compare_means(method = "anova",label.y = -2)

R_Full_simple.xlsx
Rplot

I've recently come across this problem as well. The NS. is created when stat_compare_means calls geom_signif. This seems to only occur when the p-value is exactly 1 and the upper boundary of the cut values for symnum.args is 1 as well. I simply substituted a 2 for the upper value (e.g. symnum.args <- list(cutpoints = c(0, 0.05, 2), symbols = c( "*", "ns"))) and this seems to resolve the issue.

@enricoferrero
Copy link

I also came across this problem. The string NS. is displayed for p-values equal to 1, the string ns in all other (non-significant) cases. While the latter is hidden when hide.ns = TRUE, the former is not.

@kassambara
Copy link
Owner

We'll rewrite the stat_compare_means().

The following blog posts might help to add p-values onto ggplots. Consider installing the latest dev version of rstatix and ggpubr R packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants