From 79e0b49a61f5c644bfc1607e827eedae195066a4 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 26 Mar 2024 11:02:02 +0100 Subject: [PATCH 1/4] replace hack with aesthetic --- R/geom-bar.R | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/R/geom-bar.R b/R/geom-bar.R index e4611fbabb..41f3be4a2b 100644 --- a/R/geom-bar.R +++ b/R/geom-bar.R @@ -134,6 +134,8 @@ GeomBar <- ggproto("GeomBar", GeomRect, # limits, not just those for which x and y are outside the limits non_missing_aes = c("xmin", "xmax", "ymin", "ymax"), + default_aes = aes(!!!GeomRect$default_aes, width = NULL), + setup_params = function(data, params) { params$flipped_aes <- has_flipped_aes(data, params) params @@ -158,16 +160,5 @@ GeomBar <- ggproto("GeomBar", GeomRect, flip_data(data, params$flipped_aes) }, - draw_panel = function(self, data, panel_params, coord, lineend = "butt", - linejoin = "mitre", width = NULL, flipped_aes = FALSE) { - # Hack to ensure that width is detected as a parameter - ggproto_parent(GeomRect, self)$draw_panel( - data, - panel_params, - coord, - lineend = lineend, - linejoin = linejoin - ) - }, rename_size = TRUE ) From f3fca2873c35a926bcbda7ec1328ef39685e25b0 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 26 Mar 2024 11:03:49 +0100 Subject: [PATCH 2/4] remove `width` as parameter --- R/geom-bar.R | 4 ---- R/geom-col.R | 2 -- R/stat-count.R | 2 -- 3 files changed, 8 deletions(-) diff --git a/R/geom-bar.R b/R/geom-bar.R index 41f3be4a2b..de7490bfc4 100644 --- a/R/geom-bar.R +++ b/R/geom-bar.R @@ -45,8 +45,6 @@ #' columns to the left/right of axis breaks. Note that this argument may have #' unintended behaviour when used with alternative positions, e.g. #' `position_dodge()`. -#' @param width Bar width. By default, set to 90% of the [resolution()] of the -#' data. #' @param geom,stat Override the default connection between `geom_bar()` and #' `stat_count()`. For more information about overriding these connections, #' see how the [stat][layer_stats] and [geom][layer_geoms] arguments work. @@ -98,7 +96,6 @@ geom_bar <- function(mapping = NULL, data = NULL, stat = "count", position = "stack", ..., just = 0.5, - width = NULL, na.rm = FALSE, orientation = NA, show.legend = NA, @@ -113,7 +110,6 @@ geom_bar <- function(mapping = NULL, data = NULL, inherit.aes = inherit.aes, params = list2( just = just, - width = width, na.rm = na.rm, orientation = orientation, ... diff --git a/R/geom-col.R b/R/geom-col.R index 2dc07f12da..77c756f573 100644 --- a/R/geom-col.R +++ b/R/geom-col.R @@ -4,7 +4,6 @@ geom_col <- function(mapping = NULL, data = NULL, position = "stack", ..., just = 0.5, - width = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) { @@ -19,7 +18,6 @@ geom_col <- function(mapping = NULL, data = NULL, inherit.aes = inherit.aes, params = list2( just = just, - width = width, na.rm = na.rm, ... ) diff --git a/R/stat-count.R b/R/stat-count.R index 81790d7aa1..ffb9dae3ba 100644 --- a/R/stat-count.R +++ b/R/stat-count.R @@ -13,7 +13,6 @@ stat_count <- function(mapping = NULL, data = NULL, geom = "bar", position = "stack", ..., - width = NULL, na.rm = FALSE, orientation = NA, show.legend = NA, @@ -22,7 +21,6 @@ stat_count <- function(mapping = NULL, data = NULL, params <- list2( na.rm = na.rm, orientation = orientation, - width = width, ... ) From 4bdfb3cdbef45eda3a3f7258e32f8b60bcf17e2e Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 26 Mar 2024 11:04:49 +0100 Subject: [PATCH 3/4] regenerate docs --- man/geom_bar.Rd | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/man/geom_bar.Rd b/man/geom_bar.Rd index 70c4b42437..4f0648c919 100644 --- a/man/geom_bar.Rd +++ b/man/geom_bar.Rd @@ -13,7 +13,6 @@ geom_bar( position = "stack", ..., just = 0.5, - width = NULL, na.rm = FALSE, orientation = NA, show.legend = NA, @@ -26,7 +25,6 @@ geom_col( position = "stack", ..., just = 0.5, - width = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE @@ -38,7 +36,6 @@ stat_count( geom = "bar", position = "stack", ..., - width = NULL, na.rm = FALSE, orientation = NA, show.legend = NA, @@ -111,9 +108,6 @@ columns to the left/right of axis breaks. Note that this argument may have unintended behaviour when used with alternative positions, e.g. \code{position_dodge()}.} -\item{width}{Bar width. By default, set to 90\% of the \code{\link[=resolution]{resolution()}} of the -data.} - \item{na.rm}{If \code{FALSE}, the default, missing values are removed with a warning. If \code{TRUE}, missing values are silently removed.} @@ -180,6 +174,7 @@ This geom treats each axis differently and, thus, can thus have two orientations \item \code{\link[=aes_group_order]{group}} \item \code{\link[=aes_linetype_size_shape]{linetype}} \item \code{\link[=aes_linetype_size_shape]{linewidth}} +\item \code{width} } Learn more about setting these aesthetics in \code{vignette("ggplot2-specs")}. @@ -194,6 +189,7 @@ Learn more about setting these aesthetics in \code{vignette("ggplot2-specs")}. \item \code{\link[=aes_group_order]{group}} \item \code{\link[=aes_linetype_size_shape]{linetype}} \item \code{\link[=aes_linetype_size_shape]{linewidth}} +\item \code{width} } Learn more about setting these aesthetics in \code{vignette("ggplot2-specs")}. From 66581e4b1626ca844d871e9b070409803f6676f1 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 26 Mar 2024 11:07:01 +0100 Subject: [PATCH 4/4] add news bullet --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index a96a2e4b02..f11c9981c9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # ggplot2 (development version) +* `width` is implemented as aesthetic instead of parameter in `geom_col()` and + `geom_bar()` (#3142). * `coord_map()` and `coord_polar()` throw informative warnings when used with the guide system (#5707). * When passing a function to `stat_contour(breaks)`, that function is used to