Skip to content

Commit 9c4ac34

Browse files
authored
Set width as aesthetic in geom_col()/geom_bar(). (#5807)
* replace hack with aesthetic * remove `width` as parameter * regenerate docs * add news bullet
1 parent be3ae5a commit 9c4ac34

File tree

5 files changed

+6
-25
lines changed

5 files changed

+6
-25
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
therefore stacking is not necessary (#5788).
7676
* A new `ggplot_build()` S3 method for <ggplot_built> classes was added, which
7777
returns input unaltered (@teunbrand, #5800).
78+
* `width` is implemented as aesthetic instead of parameter in `geom_col()` and
79+
`geom_bar()` (#3142).
7880

7981
# ggplot2 3.5.1
8082

R/geom-bar.R

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
#' columns to the left/right of axis breaks. Note that this argument may have
4646
#' unintended behaviour when used with alternative positions, e.g.
4747
#' `position_dodge()`.
48-
#' @param width Bar width. By default, set to 90% of the [resolution()] of the
49-
#' data.
5048
#' @param geom,stat Override the default connection between `geom_bar()` and
5149
#' `stat_count()`. For more information about overriding these connections,
5250
#' see how the [stat][layer_stats] and [geom][layer_geoms] arguments work.
@@ -98,7 +96,6 @@ geom_bar <- function(mapping = NULL, data = NULL,
9896
stat = "count", position = "stack",
9997
...,
10098
just = 0.5,
101-
width = NULL,
10299
na.rm = FALSE,
103100
orientation = NA,
104101
show.legend = NA,
@@ -113,7 +110,6 @@ geom_bar <- function(mapping = NULL, data = NULL,
113110
inherit.aes = inherit.aes,
114111
params = list2(
115112
just = just,
116-
width = width,
117113
na.rm = na.rm,
118114
orientation = orientation,
119115
...
@@ -134,6 +130,8 @@ GeomBar <- ggproto("GeomBar", GeomRect,
134130
# limits, not just those for which x and y are outside the limits
135131
non_missing_aes = c("xmin", "xmax", "ymin", "ymax"),
136132

133+
default_aes = aes(!!!GeomRect$default_aes, width = NULL),
134+
137135
setup_params = function(data, params) {
138136
params$flipped_aes <- has_flipped_aes(data, params)
139137
params
@@ -158,16 +156,5 @@ GeomBar <- ggproto("GeomBar", GeomRect,
158156
flip_data(data, params$flipped_aes)
159157
},
160158

161-
draw_panel = function(self, data, panel_params, coord, lineend = "butt",
162-
linejoin = "mitre", width = NULL, flipped_aes = FALSE) {
163-
# Hack to ensure that width is detected as a parameter
164-
ggproto_parent(GeomRect, self)$draw_panel(
165-
data,
166-
panel_params,
167-
coord,
168-
lineend = lineend,
169-
linejoin = linejoin
170-
)
171-
},
172159
rename_size = TRUE
173160
)

R/geom-col.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ geom_col <- function(mapping = NULL, data = NULL,
44
position = "stack",
55
...,
66
just = 0.5,
7-
width = NULL,
87
na.rm = FALSE,
98
show.legend = NA,
109
inherit.aes = TRUE) {
@@ -19,7 +18,6 @@ geom_col <- function(mapping = NULL, data = NULL,
1918
inherit.aes = inherit.aes,
2019
params = list2(
2120
just = just,
22-
width = width,
2321
na.rm = na.rm,
2422
...
2523
)

R/stat-count.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
stat_count <- function(mapping = NULL, data = NULL,
1414
geom = "bar", position = "stack",
1515
...,
16-
width = NULL,
1716
na.rm = FALSE,
1817
orientation = NA,
1918
show.legend = NA,
@@ -22,7 +21,6 @@ stat_count <- function(mapping = NULL, data = NULL,
2221
params <- list2(
2322
na.rm = na.rm,
2423
orientation = orientation,
25-
width = width,
2624
...
2725
)
2826

man/geom_bar.Rd

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)