Skip to content

Commit f139f40

Browse files
authored
Allow 'weight' to be dropped in stats (#5218)
* Register 'weight' as dropped aes * Add NEWS bullet
1 parent 06ca577 commit f139f40

File tree

6 files changed

+19
-6
lines changed

6 files changed

+19
-6
lines changed

NEWS.md

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

3+
* Fixed spurious warnings when the `weight` was used in `stat_bin_2d()`,
4+
`stat_boxplot()`, `stat_contour()`, `stat_bin_hex()` and `stat_quantile()`
5+
(@teunbrand, #5216).
36
* Various type checks and their messages have been standardised
47
(@teunbrand, #4834).
58
* The `layer_data()`, `layer_scales()` and `layer_grob()` now have the default

R/stat-bin2d.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ StatBin2d <- ggproto("StatBin2d", Stat,
8484
out$density <- out$count / sum(out$count, na.rm = TRUE)
8585
out$ndensity <- out$density / max(out$density, na.rm = TRUE)
8686
out
87-
}
87+
},
88+
89+
dropped_aes = "weight" # No longer available after transformation
8890
)
8991

9092
dual_param <- function(x, default = list(x = NULL, y = NULL)) {

R/stat-binhex.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ StatBinhex <- ggproto("StatBinhex", Stat,
6060
out$value <- NULL
6161

6262
out
63-
}
63+
},
64+
65+
# weight is no longer available after transformation
66+
dropped_aes = "weight"
6467
)
6568

R/stat-boxplot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ StatBoxplot <- ggproto("StatBoxplot", Stat,
5151
non_missing_aes = "weight",
5252
# either the x or y aesthetic will get dropped during
5353
# statistical transformation, depending on the orientation
54-
dropped_aes = c("x", "y"),
54+
dropped_aes = c("x", "y", "weight"),
5555
setup_data = function(self, data, params) {
5656
data <- flip_data(data, params$flipped_aes)
5757
data$x <- data$x %||% 0

R/stat-contour.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ StatContour <- ggproto("StatContour", Stat,
9090

9191
required_aes = c("x", "y", "z"),
9292
default_aes = aes(order = after_stat(level)),
93-
dropped_aes = "z", # z gets dropped during statistical transformation
93+
# z and weight get dropped during statistical transformation
94+
dropped_aes = c("z", "weight"),
9495

9596
setup_params = function(data, params) {
9697
params$z.range <- range(data$z, na.rm = TRUE, finite = TRUE)
@@ -120,7 +121,8 @@ StatContourFilled <- ggproto("StatContourFilled", Stat,
120121

121122
required_aes = c("x", "y", "z"),
122123
default_aes = aes(order = after_stat(level), fill = after_stat(level)),
123-
dropped_aes = "z", # z gets dropped during statistical transformation
124+
# z and weight get dropped during statistical transformation
125+
dropped_aes = c("z", "weight"),
124126

125127
setup_params = function(data, params) {
126128
params$z.range <- range(data$z, na.rm = TRUE, finite = TRUE)

R/stat-quantilemethods.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ StatQuantile <- ggproto("StatQuantile", Stat,
9696
method.args = method.args
9797
)
9898
vec_rbind0(!!!result)
99-
}
99+
},
100+
101+
# weight is no longer available after transformation
102+
dropped_aes = "weight"
100103
)
101104

102105
quant_pred <- function(quantile, data, method, formula, weight, grid,

0 commit comments

Comments
 (0)