Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
@@ -1,5 +1,6 @@
# ggplot2 (development version)

* `stat_summary_bin()` no longer ignores `width` parameter (@teunbrand, #4647).
* `stat_bin()` now accepts functions for argument `breaks` (@aijordan, #4561)
* (internal) The plot's layout now has a coord parameter that is used to
prevent setting up identical panel parameters (#5427)
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 @@ -74,7 +74,7 @@ StatSummaryBin <- ggproto("StatSummaryBin", Stat,
fun.max = NULL, fun.min = NULL, fun.args = list(),
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)
fun <- make_summary_fun(fun.data, fun, fun.max, fun.min, fun.args)
x <- flipped_names(flipped_aes)$x
Expand All @@ -85,7 +85,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