Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ Collate:
'stat-ellipse.R'
'stat-function.R'
'stat-identity.R'
'stat-ksmooth.R'
'stat-manual.R'
'stat-qq-line.R'
'stat-qq.R'
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export(StatEcdf)
export(StatEllipse)
export(StatFunction)
export(StatIdentity)
export(StatKsmooth)
export(StatManual)
export(StatQq)
export(StatQqLine)
Expand Down Expand Up @@ -701,6 +702,7 @@ export(stat_ecdf)
export(stat_ellipse)
export(stat_function)
export(stat_identity)
export(stat_ksmooth)
export(stat_manual)
export(stat_qq)
export(stat_qq_line)
Expand Down
32 changes: 32 additions & 0 deletions R/stat-ksmooth.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' @rdname Stat
#' @format NULL
#' @usage NULL
#' @export
StatKsmooth <- ggproto("StatKsmooth", Stat,
required_aes = c("x", "y"),
compute_group = function(data, scales, kernel = "box", bandwidth = 0.5) {
as.data.frame(ksmooth(x = data$x, y = data$y, kernel = kernel, bandwidth = bandwidth))
}
)

#' Apply kernel regression smoother
#'
#' @export
#' @inheritParams layer
#' @inheritParams geom_point
#' @inheritParams stats::ksmooth
#' @examples
#' ggplot(economics, aes(date, psavert)) +
#' geom_point(alpha = 0.25) +
#' stat_ksmooth(bandwidth = 180, kernel = "normal")
#'
stat_ksmooth <- function(mapping = NULL, data = NULL, geom = "line",
position = "identity", na.rm = FALSE, show.legend = NA,
inherit.aes = TRUE, kernel = "box", bandwidth = 0.5,
...) {
layer(
stat = StatKsmooth, data = data, mapping = mapping, geom = geom,
position = position, show.legend = show.legend, inherit.aes = inherit.aes,
params = list(kernel = kernel, bandwidth = bandwidth, ...)
)
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ reference:
- stat_ellipse
- stat_function
- stat_identity
- stat_ksmooth
- stat_summary_2d
- stat_summary_bin
- stat_unique
Expand Down
7 changes: 4 additions & 3 deletions man/Stat.Rd

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

119 changes: 119 additions & 0 deletions man/stat_ksmooth.Rd

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