Home > Mobile >  R ggplot2 - why does geom_boxplot ignore aesthetics "ymin", "lower", "middl
R ggplot2 - why does geom_boxplot ignore aesthetics "ymin", "lower", "middl

Time:11-22

For some testing purposes, I am trying to make boxplots where the upper and lower whiskers extend to the max and min data points (respectively), instead of treating them like outliers.

Not completely sure how this can be done best, but I figured I would just change my definition of upper and lower whisker to max() and min(), and pass them to geom_boxplot as ymin and ymax aesthetics (as indicated here: test

What I would expect is that the whiskers would extend to the min and max outlier data points (and hence the outliers not plotted, since they would not be outliers anymore).

Why is this happening? Am I doing something wrong? Thanks!

CodePudding user response:

Unfortunately it's not possible to provide only some of the boxplot stats. If you want to draw a boxplot manually you have to provide all stats and use stat="identity".

But to extend the whiskers over the whole data range you could use coef=Inf.

library(ggplot2)

ggplot(iris_long, aes(x = Var, y = Value))  
  geom_boxplot(aes(fill = Var),
    position = position_dodge(.9), coef = Inf
  )  
  stat_summary(fun = mean, geom = "point", shape = 5, size = 2)  
  theme_light()

enter image description here

  • Related