2626# ' or left edges of bins are included in the bin.
2727# ' @param pad If `TRUE`, adds empty bins at either end of x. This ensures
2828# ' frequency polygons touch 0. Defaults to `FALSE`.
29- # ' @param drop Treatment of zero count bins. If `"all "` (default), such
30- # ' bins are kept as-is. If `"none "`, all zero count bins are filtered out.
31- # ' If `"inner "` only zero count bins at the flanks are filtered out, but not
32- # ' in the middle. `TRUE` is shorthand for `"all"` and `FALSE` is shorthand
29+ # ' @param drop Treatment of zero count bins. If `"none "` (default), such
30+ # ' bins are kept as-is. If `"all "`, all zero count bins are filtered out.
31+ # ' If `"extremes "` only zero count bins at the flanks are filtered out, but
32+ # ' not in the middle. `TRUE` is shorthand for `"all"` and `FALSE` is shorthand
3333# ' for `"none"`.
3434# ' @eval rd_computed_vars(
3535# ' count = "number of points in bin.",
@@ -60,7 +60,7 @@ stat_bin <- function(mapping = NULL, data = NULL,
6060 closed = c(" right" , " left" ),
6161 pad = FALSE ,
6262 na.rm = FALSE ,
63- drop = " all " ,
63+ drop = " none " ,
6464 orientation = NA ,
6565 show.legend = NA ,
6666 inherit.aes = TRUE ) {
@@ -100,9 +100,10 @@ StatBin <- ggproto("StatBin", Stat,
100100 if (is.logical(params $ drop )) {
101101 params $ drop <- if (isTRUE(params $ drop )) " all" else " none"
102102 }
103+ drop <- params $ drop
103104 params $ drop <- arg_match0(
104- params $ drop %|| % " all " ,
105- c(" all" , " none" , " inner " ), arg_nm = " drop"
105+ params $ drop %|| % " none " ,
106+ c(" all" , " none" , " extremes " ), arg_nm = " drop"
106107 )
107108
108109 has_x <- ! (is.null(data $ x ) && is.null(params $ x ))
@@ -132,7 +133,7 @@ StatBin <- ggproto("StatBin", Stat,
132133 compute_group = function (data , scales , binwidth = NULL , bins = NULL ,
133134 center = NULL , boundary = NULL ,
134135 closed = c(" right" , " left" ), pad = FALSE ,
135- breaks = NULL , flipped_aes = FALSE , drop = " all " ,
136+ breaks = NULL , flipped_aes = FALSE , drop = " none " ,
136137 # The following arguments are not used, but must
137138 # be listed so parameters are computed correctly
138139 origin = NULL , right = NULL ) {
@@ -146,8 +147,8 @@ StatBin <- ggproto("StatBin", Stat,
146147
147148 keep <- switch (
148149 drop ,
149- none = bins $ count != 0 ,
150- inner = inner_runs(bins $ count != 0 ),
150+ all = bins $ count != 0 ,
151+ extremes = inner_runs(bins $ count != 0 ),
151152 TRUE
152153 )
153154 bins <- vec_slice(bins , keep )
0 commit comments