diff --git a/NEWS.md b/NEWS.md index 9f20de2a2e..c8814884a4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -73,6 +73,8 @@ therefore stacking is not necessary (#5788). * A new `ggplot_build()` S3 method for classes was added, which returns input unaltered (@teunbrand, #5800). +* `width` is implemented as aesthetic instead of parameter in `geom_col()` and + `geom_bar()` (#3142). # ggplot2 3.5.1 diff --git a/R/geom-bar.R b/R/geom-bar.R index e4611fbabb..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, ... @@ -134,6 +130,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 +156,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 ) 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 18dc1ebaa6..fd78d1beaa 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, ... ) diff --git a/man/geom_bar.Rd b/man/geom_bar.Rd index a974f9824e..4f8196b4c1 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, @@ -113,9 +110,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.} @@ -182,6 +176,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")}. @@ -196,6 +191,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")}.