Question

Here is a reproducible example, the last treatment group has one more outliers identified compared to the base boxplot.

bug1 bug2

```

dta <- structure(list(Treatment = c("A", "A", "A", "A", "A", "A", "A", 
"A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "B", 
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "C", 
"C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", 
"C", "C", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D", 
"D", "D", "D", "D", "D", "A", "A", "A", "A", "A", "A", "A", "A", 
"A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", 
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "C", "C", 
"C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", 
"C", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D", 
"D", "D", "D", "D"), `Cage No.` = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 
10, 11, 12, 13, 14, 15, 16, 101, 102, 103, 104, 105, 106, 107, 
108, 109, 110, 111, 112, 113, 114, 115, 116, 201, 202, 203, 204, 
205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 301, 
302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 
315, 316, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 
16, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 
113, 114, 115, 116, 201, 202, 203, 204, 205, 206, 207, 208, 209, 
210, 211, 212, 213, 214, 215, 216, 301, 302, 303, 304, 305, 306, 
307, 308, 309, 310, 311, 312, 313, 314, 315, 316), variable = structure(c(2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 8L, 
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L), .Label = c("Eggs Laid", 
"Eggs Cracked", "Eggs Set", "Viable Embryos", "Live 3wk Embryos", 
"Number of Hatchlings", "14 d old survivors", "Egg shell thickness", 
"Egg shell strength", "Hatchling wt", "14 d old survivor wt", 
"Food consumption (mean g/bird/day)", "Initial male wt", "Terminal male wt", 
"Initial female wt", "Terminal female wt"), class = "factor"), 
    value = c(1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 
    2, 1, 1, 2, 1, 4, 3, 1, 1, 1, 1, 1, 2, 1, 3, 1, 2, 1, 4, 
    1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
    3, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1.32126666666667, 1.36686666666667, 
    1.368, 1.34973333333333, 1.332, 1.3774, 1.36773333333333, 
    1.36006666666667, 1.35286666666667, 1.37786666666667, 1.373, 
    1.352, 1.35186666666667, 1.391, 1.37173333333333, 1.34175, 
    1.33586666666667, 1.35106666666667, 1.3622, 1.3526, 1.35506666666667, 
    1.34593333333333, 1.3446, 1.37533333333333, 1.32873333333333, 
    1.38413333333333, 1.38173333333333, 1.3572, 1.35773333333333, 
    1.3472, 1.37358333333333, 1.3568, 1.34993333333333, 1.3688, 
    1.38126666666667, 1.3638, 1.3764, 1.35786666666667, 1.3358, 
    1.35973333333333, 1.37066666666667, 1.34126666666667, 1.39126666666667, 
    1.41633333333333, 1.39593333333333, 1.3682, 1.332, 1.36606666666667, 
    1.3442, 1.3262, 1.35253333333333, 1.35066666666667, 1.37973333333333, 
    1.38166666666667, 1.35326666666667, 1.3518, 1.34486666666667, 
    1.36173333333333, 1.4026, 1.33053333333333, 1.3356, 1.34375, 
    1.34146666666667, 1.37606666666667)), .Names = c("Treatment", 
"Cage No.", "variable", "value"), class = "data.frame", row.names = c(65L, 
66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 
79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 
92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 103L, 
104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 114L, 
115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L, 125L, 
126L, 127L, 128L, 449L, 450L, 451L, 452L, 453L, 454L, 455L, 456L, 
457L, 458L, 459L, 460L, 461L, 462L, 463L, 464L, 465L, 466L, 467L, 
468L, 469L, 470L, 471L, 472L, 473L, 474L, 475L, 476L, 477L, 478L, 
479L, 480L, 481L, 482L, 483L, 484L, 485L, 486L, 487L, 488L, 489L, 
490L, 491L, 492L, 493L, 494L, 495L, 496L, 497L, 498L, 499L, 500L, 
501L, 502L, 503L, 504L, 505L, 506L, 507L, 508L, 509L, 510L, 511L, 
512L))

ggplot(data=subset(dta,variable=="Egg shell thickness"),aes(x=Treatment,y=value,fill=Treatment))+stat_boxplot(geom ='errorbar')+geom_boxplot()
windows()
boxplot(value~Treatment,data=subset(dta,variable=="Egg shell thickness"))

ggplot(data=subset(dta,variable=="Eggs Cracked"),aes(x=Treatment,y=value,fill=Treatment))+stat_boxplot(geom ='errorbar')+geom_boxplot()
windows()
boxplot(value~Treatment,data=subset(dta,variable=="Eggs Cracked"))

```

Was it helpful?

Solution

The calculation method for the hinges is different. geom_boxplot() uses actual 1st & third quantiles, boxplot() uses a version of this which is not the same for even n.

This is well documented in both ?geom_boxplot and ?boxplot.stats

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top