diff --git a/NEWS.md b/NEWS.md index f011be0059..c460be148b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # ggplot2 (development version) +* Fixed spurious warnings when the `weight` was used in `stat_bin_2d()`, + `stat_boxplot()`, `stat_contour()`, `stat_bin_hex()` and `stat_quantile()` + (@teunbrand, #5216). * Various type checks and their messages have been standardised (@teunbrand, #4834). * The `layer_data()`, `layer_scales()` and `layer_grob()` now have the default diff --git a/R/stat-bin2d.R b/R/stat-bin2d.R index c0732ef7a8..69f57ebee3 100644 --- a/R/stat-bin2d.R +++ b/R/stat-bin2d.R @@ -84,7 +84,9 @@ StatBin2d <- ggproto("StatBin2d", Stat, out$density <- out$count / sum(out$count, na.rm = TRUE) out$ndensity <- out$density / max(out$density, na.rm = TRUE) out - } + }, + + dropped_aes = "weight" # No longer available after transformation ) dual_param <- function(x, default = list(x = NULL, y = NULL)) { diff --git a/R/stat-binhex.R b/R/stat-binhex.R index 867194b4ed..96f727380e 100644 --- a/R/stat-binhex.R +++ b/R/stat-binhex.R @@ -60,6 +60,9 @@ StatBinhex <- ggproto("StatBinhex", Stat, out$value <- NULL out - } + }, + + # weight is no longer available after transformation + dropped_aes = "weight" ) diff --git a/R/stat-boxplot.R b/R/stat-boxplot.R index c8b39db465..9d6887ddae 100644 --- a/R/stat-boxplot.R +++ b/R/stat-boxplot.R @@ -51,7 +51,7 @@ StatBoxplot <- ggproto("StatBoxplot", Stat, non_missing_aes = "weight", # either the x or y aesthetic will get dropped during # statistical transformation, depending on the orientation - dropped_aes = c("x", "y"), + dropped_aes = c("x", "y", "weight"), setup_data = function(self, data, params) { data <- flip_data(data, params$flipped_aes) data$x <- data$x %||% 0 diff --git a/R/stat-contour.R b/R/stat-contour.R index 6df82e4eae..5791938d0f 100644 --- a/R/stat-contour.R +++ b/R/stat-contour.R @@ -90,7 +90,8 @@ StatContour <- ggproto("StatContour", Stat, required_aes = c("x", "y", "z"), default_aes = aes(order = after_stat(level)), - dropped_aes = "z", # z gets dropped during statistical transformation + # z and weight get dropped during statistical transformation + dropped_aes = c("z", "weight"), setup_params = function(data, params) { params$z.range <- range(data$z, na.rm = TRUE, finite = TRUE) @@ -120,7 +121,8 @@ StatContourFilled <- ggproto("StatContourFilled", Stat, required_aes = c("x", "y", "z"), default_aes = aes(order = after_stat(level), fill = after_stat(level)), - dropped_aes = "z", # z gets dropped during statistical transformation + # z and weight get dropped during statistical transformation + dropped_aes = c("z", "weight"), setup_params = function(data, params) { params$z.range <- range(data$z, na.rm = TRUE, finite = TRUE) diff --git a/R/stat-quantilemethods.R b/R/stat-quantilemethods.R index 74dc358747..f22b4ec687 100644 --- a/R/stat-quantilemethods.R +++ b/R/stat-quantilemethods.R @@ -96,7 +96,10 @@ StatQuantile <- ggproto("StatQuantile", Stat, method.args = method.args ) vec_rbind0(!!!result) - } + }, + + # weight is no longer available after transformation + dropped_aes = "weight" ) quant_pred <- function(quantile, data, method, formula, weight, grid,