Skip to content

wrong detection of outlier with ggplot #6017

Closed
@BegoniaCampos

Description

@BegoniaCampos

I found that using the same data, an outlier was detected when plotting a boxplot with "ggplot" but not with "boxplot" (base). Therefore, I performed the upper and lower inner fences calculations following Tukey (1977) and no observations in group A met the outlier criterion.
boxplot-outlier
What am I missing?
Here is the code to reproduce the bug:

Groups <- factor(c(rep("A",4),rep("B",4)))
yA <- c(1.186, 1.189, 1.191, 1.206)
yB <- c(1.182, 1.185, 1.193, 1.201)
y <- c(yA, yB)dd <- data.frame(Groups, y)
boxplot(y~Groups)
ggplot(data = dd, aes(x = factor(Groups), y = y)) + geom_boxplot()
boxplot.stats(subset(dd$y,Groups=="A"))$out
fivenum(subset(dd$y,Groups=="A"))  #Tukey 1977 
#
reprex::reprex()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions