Skip to content

Commit 39274b4

Browse files
committed
Warning message for binwidth + geom_bar.
Fixes #1391
1 parent 144aea1 commit 39274b4

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

R/geom-bar.r

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#' @export
2929
#' @inheritParams geom_point
3030
#' @param width Bar width. By default, set to 90\% of the resolution of the data.
31+
#' @param binwidth \code{geom_bar} no longer has a binwidth argument - if
32+
#' you use it you'll get an warning telling to you use
33+
#' \code{\link{geom_histogram}} instead.
3134
#' @param geom,stat Override the default connection between \code{geom_bar} and
3235
#' \code{stat_count}.
3336
#' @examples
@@ -71,8 +74,17 @@
7174
#' ggplot(mpg, aes(reorder_size(class))) + geom_bar()
7275
#' }
7376
geom_bar <- function(mapping = NULL, data = NULL, stat = "count",
74-
position = "stack", width = NULL, ...,
77+
position = "stack", width = NULL, binwidth = NULL, ...,
7578
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) {
79+
80+
if (!is.null(binwidth)) {
81+
warning("`geom_bar()` no longer has a `binwidth` parameter. ",
82+
"Please use `geom_histogram()` instead.", call. = "FALSE")
83+
return(geom_histogram(mapping = mapping, data = data,
84+
position = position, width = width, binwidth = binwidth, ...,
85+
na.rm = na.rm, show.legend = show.legend, inherit.aes = inherit.aes))
86+
}
87+
7688
layer(
7789
data = data,
7890
mapping = mapping,

man/geom_bar.Rd

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)