Skip to content

Commit cf5733c

Browse files
committed
Merge branch 'master' of github.com:ThierryO/ggplot2 into ThierryO-master
Conflicts: R/geom-boxplot.r man/geom_boxplot.Rd
2 parents 80847bb + 89c6420 commit cf5733c

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ ggplot2 0.9.3.1.99
6464

6565
* Add `"none"` to documentation of `theme()` for parameter `legend.position`
6666
(@krlmlr, #829).
67+
* The outliers of geom_boxplot() use the default colour, size and shape from
68+
geom_point(). Changing the defaults of geom_point() with
69+
update_geom_defaults() will apply the same changes to the outliers of
70+
geom_boxplot(). Changing the defaults for the outliers was previously not
71+
possible. (@ThierryO, #757)
6772

6873
ggplot2 0.9.3.1
6974
----------------------------------------------------------------

R/geom-boxplot.r

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
#' continuous variable, \code{\link{geom_jitter}} for another way to look
2424
#' at conditional distributions"
2525
#' @inheritParams geom_point
26-
#' @param outlier.colour colour for outlying points
27-
#' @param outlier.shape shape of outlying points
28-
#' @param outlier.size size of outlying points
26+
#' @param outlier.colour colour for outlying points. Uses the default from geom_point().
27+
#' @param outlier.shape shape of outlying points. Uses the default from geom_point().
28+
#' @param outlier.size size of outlying points. Uses the default from geom_point().
2929
#' @param notch if \code{FALSE} (default) make a standard box plot. If
3030
#' \code{TRUE}, make a notched box plot. Notches are used to compare groups;
3131
#' if the notches of two boxes do not overlap, this is strong evidence that
@@ -100,13 +100,30 @@
100100
#' # Using varwidth
101101
#' p + geom_boxplot(varwidth = TRUE)
102102
#' qplot(factor(cyl), mpg, data = mtcars, geom = "boxplot", varwidth = TRUE)
103+
#'
104+
#' # Update the defaults for the outliers by changing the defaults for geom_point
105+
#'
106+
#' p <- ggplot(mtcars, aes(factor(cyl), mpg))
107+
#' p + geom_boxplot()
108+
#'
109+
#' update_geom_defaults("point", list(shape = 1, colour = "red", size = 5))
110+
#' p + geom_boxplot()
103111
#' }
104-
geom_boxplot <- function (mapping = NULL, data = NULL, stat = "boxplot", position = "dodge",
105-
outlier.colour = "black", outlier.shape = 16, outlier.size = 2,
106-
notch = FALSE, notchwidth = .5, varwidth = FALSE, ...) {
112+
geom_boxplot <- function (mapping = NULL, data = NULL, stat = "boxplot",
113+
position = "dodge", outlier.colour = NULL,
114+
outlier.shape = NULL, outlier.size = NULL,
115+
notch = FALSE, notchwidth = .5, ...) {
116+
117+
outlier_defaults <- Geom$find('point')$default_aes()
118+
119+
outlier.colour <- outlier.colour %||% outlier_defaults$colour
120+
outlier.shape <- outlier.shape %||% outlier_defaults$shape
121+
outlier.size <- outlier.size %||% outlier_defaults$size
122+
107123
GeomBoxplot$new(mapping = mapping, data = data, stat = stat,
108-
position = position, outlier.colour = outlier.colour, outlier.shape = outlier.shape,
109-
outlier.size = outlier.size, notch = notch, notchwidth = notchwidth, varwidth = varwidth, ...)
124+
position = position, outlier.colour = outlier.colour,
125+
outlier.shape = outlier.shape, outlier.size = outlier.size, notch = notch,
126+
notchwidth = notchwidth, ...)
110127
}
111128

112129
GeomBoxplot <- proto(Geom, {

man/geom_boxplot.Rd

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
\title{Box and whiskers plot.}
55
\usage{
66
geom_boxplot(mapping = NULL, data = NULL, stat = "boxplot",
7-
position = "dodge", outlier.colour = "black", outlier.shape = 16,
8-
outlier.size = 2, notch = FALSE, notchwidth = 0.5, varwidth = FALSE,
9-
...)
7+
position = "dodge", outlier.colour = NULL, outlier.shape = NULL,
8+
outlier.size = NULL, notch = FALSE, notchwidth = 0.5, ...)
109
}
1110
\arguments{
12-
\item{outlier.colour}{colour for outlying points}
11+
\item{outlier.colour}{colour for outlying points. Uses the default from geom_point().}
1312

14-
\item{outlier.shape}{shape of outlying points}
13+
\item{outlier.shape}{shape of outlying points. Uses the default from geom_point().}
1514

16-
\item{outlier.size}{size of outlying points}
15+
\item{outlier.size}{size of outlying points. Uses the default from geom_point().}
1716

1817
\item{notch}{if \code{FALSE} (default) make a standard box plot. If
1918
\code{TRUE}, make a notched box plot. Notches are used to compare groups;
@@ -126,6 +125,14 @@ b + geom_boxplot(aes(fill = X1), stat = "identity")
126125
# Using varwidth
127126
p + geom_boxplot(varwidth = TRUE)
128127
qplot(factor(cyl), mpg, data = mtcars, geom = "boxplot", varwidth = TRUE)
128+
129+
# Update the defaults for the outliers by changing the defaults for geom_point
130+
131+
p <- ggplot(mtcars, aes(factor(cyl), mpg))
132+
p + geom_boxplot()
133+
134+
update_geom_defaults("point", list(shape = 1, colour = "red", size = 5))
135+
p + geom_boxplot()
129136
}
130137
}
131138
\references{

0 commit comments

Comments
 (0)