Skip to content

Commit 2d163ae

Browse files
committed
Outlier arguments are parameters not aesthetics.
Fixes #1400. Also changed the default outlier color to match box colour, and updated the docs.
1 parent 0c8b7e5 commit 2d163ae

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ All defunct functions have been removed.
175175

176176
* `geom_bar()` and `geom_rect()` use a slightly paler shade of grey so they
177177
aren't so visually heavy.
178+
179+
* `geom_boxplot()` now colours outliers the same way as the boxes.
178180

179181
* `geom_point()` now uses shape 19 instead of 16. This looks much better on
180182
the default Linux graphics device. (It's very slightly smaller than the old

R/geom-boxplot.r

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,9 @@
2525
#' @inheritParams geom_point
2626
#' @param geom,stat Use to override the default connection between
2727
#' \code{geom_boxplot} and \code{stat_boxplot}.
28-
#' @param outlier.colour Override aesthetics used for the outliers. Defaults
29-
#' come from \code{geom_point()}.
30-
#' @param outlier.shape Override aesthetics used for the outliers. Defaults
31-
#' come from \code{geom_point()}.
32-
#' @param outlier.size Override aesthetics used for the outliers. Defaults
33-
#' come from \code{geom_point()}.
34-
#' @param outlier.stroke Override aesthetics used for the outliers. Defaults
35-
#' come from \code{geom_point()}.
28+
#' @param outlier.colour,outlier.shape,outlier.size,outlier.stroke Default
29+
#' aesthetics for outliers. Set to \code{NULL} to inherit from the aesthetics
30+
#' used for the box.
3631
#' @param notch if \code{FALSE} (default) make a standard box plot. If
3732
#' \code{TRUE}, make a notched box plot. Notches are used to compare groups;
3833
#' if the notches of two boxes do not overlap, this suggests that the medians
@@ -55,10 +50,12 @@
5550
#' p + geom_boxplot(notch = TRUE)
5651
#' p + geom_boxplot(varwidth = TRUE)
5752
#' p + geom_boxplot(fill = "white", colour = "#3366FF")
53+
#' # By default, outlier points match the colour of the box. Use
54+
#' # outlier.colour to override
5855
#' p + geom_boxplot(outlier.colour = "red", outlier.shape = 1)
5956
#'
6057
#' # Boxplots are automatically dodged when any aesthetic is a factor
61-
#' p + geom_boxplot(aes(fill = drv))
58+
#' p + geom_boxplot(aes(colour = drv))
6259
#'
6360
#' # You can also use boxplots with continuous x, as long as you supply
6461
#' # a grouping variable. cut_width is particularly useful
@@ -86,7 +83,7 @@
8683
#' )
8784
#' }
8885
geom_boxplot <- function(mapping = NULL, data = NULL, stat = "boxplot",
89-
position = "dodge", outlier.colour = "black",
86+
position = "dodge", outlier.colour = NULL,
9087
outlier.shape = 19, outlier.size = 1.5,
9188
outlier.stroke = 0.5, notch = FALSE, notchwidth = 0.5,
9289
varwidth = FALSE, na.rm = FALSE,
@@ -152,6 +149,7 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom,
152149
outlier.colour = "black", outlier.shape = 19,
153150
outlier.size = 1.5, outlier.stroke = 0.5,
154151
notch = FALSE, notchwidth = 0.5, varwidth = FALSE) {
152+
155153
common <- data.frame(
156154
colour = data$colour,
157155
size = data$size,
@@ -212,8 +210,7 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom,
212210
draw_key = draw_key_boxplot,
213211

214212
default_aes = aes(weight = 1, colour = "grey20", fill = "white", size = 0.5,
215-
alpha = NA, shape = 19, linetype = "solid", outlier.colour = "black",
216-
outlier.shape = 19, outlier.size = 1.5, outlier.stroke = 0.5),
213+
alpha = NA, shape = 19, linetype = "solid"),
217214

218215
required_aes = c("x", "lower", "upper", "middle", "ymin", "ymax")
219216
)

man/geom_boxplot.Rd

Lines changed: 7 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)