Skip to content
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
* {tibble} is now suggested instead of imported (@teunbrand, #5986)
* The ellipsis argument is now checked in `fortify()`, `get_alt_text()`,
`labs()` and several guides (@teunbrand, #3196).
* `stat_summary_bin()` no longer ignores `width` parameter (@teunbrand, #4647).

# ggplot2 3.5.1

Expand Down
4 changes: 2 additions & 2 deletions R/stat-summary-bin.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ StatSummaryBin <- ggproto("StatSummaryBin", Stat,
compute_group = function(data, scales, fun = NULL,
bins = 30, binwidth = NULL, breaks = NULL,
origin = NULL, right = FALSE, na.rm = FALSE,
flipped_aes = FALSE) {
flipped_aes = FALSE, width = NULL) {
data <- flip_data(data, flipped_aes)
x <- flipped_names(flipped_aes)$x
breaks <- bin2d_breaks(scales[[x]], breaks, origin, binwidth, bins, right = right)
Expand All @@ -89,7 +89,7 @@ StatSummaryBin <- ggproto("StatSummaryBin", Stat,

locs <- bin_loc(breaks, out$bin)
out$x <- locs$mid
out$width <- if (scales[[x]]$is_discrete()) 0.9 else locs$length
out$width <- width %||% if (scales[[x]]$is_discrete()) 0.9 else locs$length
out$flipped_aes <- flipped_aes
flip_data(out, flipped_aes)
}
Expand Down
10 changes: 9 additions & 1 deletion tests/testthat/test-stat-summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ test_that("stat_summary(_bin) work with lambda expressions", {

})

test_that("stat_summary_bin takes user's `width` argument (#4647)", {
p <- ggplot(mtcars, aes(mpg, disp)) +
stat_summary_bin(
fun.data = mean_se, na.rm = TRUE,
binwidth = 1, width = 2
)


ld <- layer_data(p)
expect_equal(unique(ld$width), 2)
})

test_that("stat_summary_(2d|hex) work with lambda expressions", {

Expand Down
Loading