rggboxplot

ggboxplot - why do the lines (whiskers) end within the box?


enter image description here

I think it may be a easy question, but I could not find the solution in any descriptions of the package. I used ggboxplot from the ggpubr package to draw boxplots of my data. My problem is that the lines, I think it represents the whiskers (?!) of the box plot, ends within the box plot (see picture). I was wondering if this is correct and if so, how these lines are calculated? Or did I do something wrong? I would be very happy if anyone could help me out here.

If it helps to find an error. I used this code to respresent my data:

stat.test <- DS1%>%group_by(PS)%>%
  t_test(y ~ x, paired = FALSE) %>%
  adjust_pvalue(method = "holm") %>%
  add_significance()
myplot <- ggboxplot(
  DS1, x = "x", y = "y",
  fill = "x", palette = c("#FF9333","#CCCCCC"), add="mean_sd", legend = "none",ylab = "y", xlab= "x",
  ggtheme = theme_pubr(border = TRUE)) +
  facet_wrap(~PS="free")+
  theme(axis.text = element_text( size = 12 ),
        axis.title = element_text( size = 15),
        strip.text = element_text(size = 15))
# Add statistical test p-values
stat.test <- stat.test %>% add_xy_position(x = "x")
myplot + stat_pvalue_manual(stat.test, label = "p.adj.signif")

Solution

  • The lines you are seeing inside the boxes are the error bars from mean_sd. Whiskers are drawn only outside of the boxes.

    Your dataset must have no data points beyond the 75th centile in the orange group so no whisker is needed at all there.

    You could confirm this by switching off the mean_sd addition, or by using (eg) add.params = list(color="red") to check that it is in fact the error bars being drawn.

    In general it probably isn't helpful to overlay mean and sd onto a box plot.