Skip to content

Commit 11279f6

Browse files
committed
Only draw outliers when present
1 parent e8f9302 commit 11279f6

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

R/geom-boxplot.r

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,26 @@ GeomBoxplot <- proto(Geom, {
1717
stringsAsFactors = FALSE
1818
))
1919
defaults2 <- defaults[c(1,1), ]
20-
21-
with(data, ggname(.$my_name(), gTree(children = gList(
22-
if(length(outliers[[1]]) >= 1) GeomPoint$draw(data.frame(y = outliers[[1]], x = x[rep(1, length(outliers[[1]]))], colour=I(outlier.colour), shape=outlier.shape, size=outlier.size, fill = NA), ...),
20+
21+
if (!is.null(data$outliers) && length(data$outliers[[1]] >= 1)) {
22+
outliers_grob <- with(data,
23+
GeomPoint$draw(data.frame(
24+
y = outliers[[1]], x = x[rep(1, length(outliers[[1]]))],
25+
colour=I(outlier.colour), shape = outlier.shape,
26+
size = outlier.size, fill = NA), ...
27+
)
28+
)
29+
} else {
30+
outliers_grob <- NULL
31+
}
32+
33+
with(data, ggname(.$my_name(), grobTree(
34+
outliers_grob,
2335
GeomPath$draw(data.frame(y=c(upper, ymax), defaults2), ...),
2436
GeomPath$draw(data.frame(y=c(lower, ymin), defaults2), ...),
2537
GeomBar$draw(data.frame(ymax = upper, ymin = lower, defaults), ...),
2638
GeomBar$draw(data.frame(ymax = middle, ymin = middle, defaults), ...)
27-
))))
39+
)))
2840
}
2941

3042
objname <- "boxplot"

0 commit comments

Comments
 (0)