Skip to content

Commit 7f1f0e4

Browse files
committed
Add bw argument to stat_ydensity
For consistency with stat_density
1 parent 87d5cc7 commit 7f1f0e4

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

R/stat-ydensity.r

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#' @export
1919
#' @rdname geom_violin
2020
stat_ydensity <- function(mapping = NULL, data = NULL, geom = "violin",
21-
position = "dodge", adjust = 1, kernel = "gaussian",
21+
position = "dodge", bw = "nrd0", adjust = 1, kernel = "gaussian",
2222
trim = TRUE, scale = "area", na.rm = FALSE,
2323
show.legend = NA, inherit.aes = TRUE, ...) {
2424
scale <- match.arg(scale, c("area", "count", "width"))
@@ -32,6 +32,7 @@ stat_ydensity <- function(mapping = NULL, data = NULL, geom = "violin",
3232
show.legend = show.legend,
3333
inherit.aes = inherit.aes,
3434
params = list(
35+
bw = bw,
3536
adjust = adjust,
3637
kernel = kernel,
3738
trim = trim,
@@ -51,7 +52,7 @@ StatYdensity <- ggproto("StatYdensity", Stat,
5152
required_aes = c("x", "y"),
5253
non_missing_aes = "weight",
5354

54-
compute_group = function(data, scales, width = NULL, adjust = 1,
55+
compute_group = function(data, scales, width = NULL, bw = "nrd0", adjust = 1,
5556
kernel = "gaussian", trim = TRUE, na.rm = FALSE) {
5657
if (nrow(data) < 3) return(data.frame())
5758

@@ -61,7 +62,7 @@ StatYdensity <- ggproto("StatYdensity", Stat,
6162
range <- scales$y$dimension()
6263
}
6364
dens <- compute_density(data$y, data$w, from = range[1], to = range[2],
64-
adjust = adjust, kernel = kernel)
65+
bw = bw, adjust = adjust, kernel = kernel)
6566

6667
dens$y <- dens$x
6768
dens$x <- mean(range(data$x))
@@ -75,11 +76,11 @@ StatYdensity <- ggproto("StatYdensity", Stat,
7576
dens
7677
},
7778

78-
compute_panel = function(self, data, scales, width = NULL, adjust = 1,
79+
compute_panel = function(self, data, scales, width = NULL, bw = "nrd0", adjust = 1,
7980
kernel = "gaussian", trim = TRUE, na.rm = FALSE,
8081
scale = "area") {
8182
data <- ggproto_parent(Stat, self)$compute_panel(
82-
data, scales, width = width, adjust = adjust, kernel = kernel,
83+
data, scales, width = width, bw = bw, adjust = adjust, kernel = kernel,
8384
trim = trim, na.rm = na.rm
8485
)
8586

man/geom_violin.Rd

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

0 commit comments

Comments
 (0)