Skip to content

Set width as aesthetic in geom_col()/geom_bar(). #5807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
therefore stacking is not necessary (#5788).
* A new `ggplot_build()` S3 method for <ggplot_built> 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

Expand Down
17 changes: 2 additions & 15 deletions R/geom-bar.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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,
...
Expand All @@ -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
Expand All @@ -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
)
2 changes: 0 additions & 2 deletions R/geom-col.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
...
)
Expand Down
2 changes: 0 additions & 2 deletions R/stat-count.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22,7 +21,6 @@ stat_count <- function(mapping = NULL, data = NULL,
params <- list2(
na.rm = na.rm,
orientation = orientation,
width = width,
...
)

Expand Down
8 changes: 2 additions & 6 deletions man/geom_bar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading