Skip to content

Commit bc2a2a5

Browse files
committed
Add default to stat_summary.
Fixes #1386
1 parent 1ee49e2 commit bc2a2a5

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838

3939
* New `stat_summary_bin()` works like `stat_summary()` but on binned data.
4040
It's a generalisation of `stat_bin()` that can compute any aggregate,
41-
not just counts (#1274).
41+
not just counts (#1274). Both default to `mean_se()` if no aggregation
42+
functions are supplied (#1386).
4243

4344
* Layers are now much stricter about their arguments - you will get an error
4445
if you've supplied an argument that isn't an aesthetic or a parameter.

R/stat-summary-bin.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ make_summary_fun <- function(fun.data, fun.y, fun.ymax, fun.ymin, fun.args) {
5959
function(df) {
6060
do.call(fun.data, c(list(quote(df$y)), fun.args))
6161
}
62-
} else {
62+
} else if (!is.null(fun.y) || !is.null(fun.ymax) || !is.null(fun.ymin)) {
6363
# Three functions that take vectors as inputs
6464

6565
call_f <- function(fun, x) {
@@ -74,5 +74,10 @@ make_summary_fun <- function(fun.data, fun.y, fun.ymax, fun.ymin, fun.args) {
7474
ymax = call_f(fun.ymax, df$y)
7575
)
7676
}
77+
} else {
78+
message("No summary function supplied, defaulting to `mean_se()")
79+
function(df) {
80+
mean_se(df$y)
81+
}
7782
}
7883
}

R/stat-summary.r

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#' number, but is somewhat less flexible. If your summary function computes
3232
#' multiple values at once (e.g. ymin and ymax), use \code{fun.data}.
3333
#'
34+
#' If no aggregation functions are suppled, will default to
35+
#' \code{\link{mean_se}}.
36+
#'
3437
#' @param fun.data A function that is given the complete data and should
3538
#' return a data frame with variables \code{ymin}, \code{y}, and \code{ymax}.
3639
#' @param fun.ymin,fun.y,fun.ymax Alternatively, supply three individual

man/stat_summary.Rd

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

0 commit comments

Comments
 (0)