Skip to content

Commit

Permalink
default formula argument to NULL in geom_smooth(); closes #3205
Browse files Browse the repository at this point in the history
  • Loading branch information
bfgray3 committed May 7, 2019
1 parent 3b69172 commit 508e1bc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ core developer team.

## Minor improvements and bug fixes

* The `formula` argument to `geom_smooth()` now defaults to `NULL` and is filled in with the approprate formula in the function body (@bfgray3, #3205).

* `cut_width()` now accepts `...` to pass further arguments to `base::cut.default()`
like `cut_number()` and `cut_interval()` already did (@cderv, #3055)

Expand Down
2 changes: 1 addition & 1 deletion R/geom-smooth.r
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ geom_smooth <- function(mapping = NULL, data = NULL,
stat = "smooth", position = "identity",
...,
method = "auto",
formula = y ~ x,
formula = NULL,
se = TRUE,
na.rm = FALSE,
show.legend = NA,
Expand Down
11 changes: 7 additions & 4 deletions R/stat-smooth.r
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#' model that `method = "auto"` would use, then set
#' `method = "gam", formula = y ~ s(x, bs = "cs")`.
#' @param formula Formula to use in smoothing function, eg. `y ~ x`,
#' `y ~ poly(x, 2)`, `y ~ log(x)`
#' `y ~ poly(x, 2)`, `y ~ log(x)`. `NULL` by default, in which case
#' `method = "auto"` implies `formula = y ~ x` when there are fewer than 1,000
#' observations and `formula = y ~ s(x, bs = "cs")` otherwise.
#' @param se Display confidence interval around smooth? (`TRUE` by default, see
#' `level` to control.)
#' @param fullrange Should the fit span the full range of the plot, or just
Expand All @@ -38,7 +40,7 @@ stat_smooth <- function(mapping = NULL, data = NULL,
geom = "smooth", position = "identity",
...,
method = "auto",
formula = y ~ x,
formula = NULL,
se = TRUE,
n = 80,
span = 0.75,
Expand Down Expand Up @@ -86,9 +88,10 @@ StatSmooth <- ggproto("StatSmooth", Stat,

if (max_group < 1000) {
params$method <- "loess"
params$formula <- params$formula %||% (y ~ x)
} else {
params$method <- "gam"
params$formula <- y ~ s(x, bs = "cs")
params$formula <- params$formula %||% (y ~ s(x, bs = "cs"))
}
message("`geom_smooth()` using method = '", params$method,
"' and formula '", deparse(params$formula), "'")
Expand All @@ -100,7 +103,7 @@ StatSmooth <- ggproto("StatSmooth", Stat,
params
},

compute_group = function(data, scales, method = "auto", formula = y~x,
compute_group = function(data, scales, method = "auto", formula = NULL,
se = TRUE, n = 80, span = 0.75, fullrange = FALSE,
xseq = NULL, level = 0.95, method.args = list(),
na.rm = FALSE) {
Expand Down
8 changes: 5 additions & 3 deletions man/geom_smooth.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 508e1bc

Please sign in to comment.