Skip to content

Commit 7caada4

Browse files
authored
Require x *or* y in stat_ydensity() (#6645)
* populate x/y with 0 if absent * add news bullet
1 parent 6ea6ead commit 7caada4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ggplot2 (development version)
22

3+
* `stat_ydensity()` now only requires the `x` or `y` aesthetic. The other will
4+
be populated with 0, similar to `stat_boxplot()` (@teunbrand, #6600)
35
* Implemented `as.list()` and `S7::convert()` methods for lists and classes in ggplot2
46
(@teunbrand, #6695)
57
* The default linetype in `geom_sf()` is derived from `geom_polygon()` for

R/stat-ydensity.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#' @export
55
StatYdensity <- ggproto(
66
"StatYdensity", Stat,
7-
required_aes = c("x", "y"),
7+
required_aes = "x|y",
88
non_missing_aes = "weight",
99

1010
setup_params = function(data, params) {
@@ -23,6 +23,12 @@ StatYdensity <- ggproto(
2323
params
2424
},
2525

26+
setup_data = function(self, data, params) {
27+
var <- flipped_names(flip = params$flipped_aes)$x
28+
data[[var]] <- data[[var]] %||% 0
29+
data
30+
},
31+
2632
# `draw_quantiles` is here for deprecation repair reasons
2733
extra_params = c("na.rm", "orientation", "draw_quantiles"),
2834

0 commit comments

Comments
 (0)