Skip to content

Commit 5ce5fd8

Browse files
committed
Rename stat_bar to stat_count
1 parent 8594000 commit 5ce5fd8

File tree

6 files changed

+31
-28
lines changed

6 files changed

+31
-28
lines changed

NAMESPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ export(ScaleDiscrete)
176176
export(ScaleDiscreteIdentity)
177177
export(ScaleDiscretePosition)
178178
export(Stat)
179-
export(StatBar)
180179
export(StatBin)
181180
export(StatBin2d)
182181
export(StatBindot)
183182
export(StatBinhex)
184183
export(StatBoxplot)
185184
export(StatContour)
185+
export(StatCount)
186186
export(StatDensity)
187187
export(StatDensity2d)
188188
export(StatEcdf)
@@ -415,14 +415,14 @@ export(scale_y_log10)
415415
export(scale_y_reverse)
416416
export(scale_y_sqrt)
417417
export(should_stop)
418-
export(stat_bar)
419418
export(stat_bin)
420419
export(stat_bin2d)
421420
export(stat_bin_2d)
422421
export(stat_bin_hex)
423422
export(stat_binhex)
424423
export(stat_boxplot)
425424
export(stat_contour)
425+
export(stat_count)
426426
export(stat_density)
427427
export(stat_density2d)
428428
export(stat_ecdf)

NEWS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ ggplot2 1.0.1.9xxx
9393
default values once per layer, rather than once per panel (#1220).
9494

9595
* `geom_bar()` and `geom_histogram()` no longer share `stat_bin()`. Now
96-
`geom_bar()` has its own stat, `stat_bar()`. This is useful if you want to
96+
`geom_bar()` has its own stat, `stat_coont()`. This is useful if you want to
9797
display a bar chart of continuous data, drawing a bar at each unique
9898
location.
9999

R/geom-bar.r

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#' Bars, rectangles with bases on x-axis
22
#'
33
#' There are two types of bar charts, determined by what is mapped to bar
4-
#' height. By default, \code{geom_bar} uses \code{stat = "bar"} which makes the
5-
#' height of the bar proportion to the number of cases in each group (or
6-
#' if the \code{weight} aethetic is supplied, the sum of the weights).
7-
# If you want the heights of the bars to represent values in the data, use
4+
#' height. By default, \code{geom_bar} uses \code{stat = "count"} which makes
5+
#' the height of the bar proportion to the number of cases in each group (or if
6+
#' the \code{weight} aethetic is supplied, the sum of the weights). If you want
7+
#' the heights of the bars to represent values in the data, use
88
#' \code{stat="identity"} and map a variable to the \code{y} aesthetic.
99
#'
1010
#' A bar chart maps the height of the bar to a variable, and so the base of
@@ -29,7 +29,7 @@
2929
#' @param width Bar width. By default, set of 90% of the resolution of the
3030
#' data.
3131
#' @param geom,stat Override the default connection between \code{geom_bar} and
32-
#' \code{stat_bar}.
32+
#' \code{stat_count}.
3333
#' @examples
3434
#' # geom_bar is designed to make it easy to create bar charts that show
3535
#' # counts (or sums of weights)
@@ -70,7 +70,7 @@
7070
#' }
7171
#' ggplot(mpg, aes(reorder_size(class))) + geom_bar()
7272
#' }
73-
geom_bar <- function(mapping = NULL, data = NULL, stat = "bar",
73+
geom_bar <- function(mapping = NULL, data = NULL, stat = "count",
7474
position = "stack", width = NULL, ...,
7575
show.legend = NA, inherit.aes = TRUE) {
7676
layer(
@@ -118,13 +118,13 @@ GeomBar <- ggproto("GeomBar", GeomRect,
118118
#' \item{count}{number of points in bin}
119119
#' \item{prop}{groupwise proportion}
120120
#' }
121-
stat_bar <- function(mapping = NULL, data = NULL, geom = "bar",
121+
stat_count <- function(mapping = NULL, data = NULL, geom = "bar",
122122
position = "stack", width = NULL, ...,
123123
show.legend = NA, inherit.aes = TRUE) {
124124
layer(
125125
data = data,
126126
mapping = mapping,
127-
stat = StatBar,
127+
stat = StatCount,
128128
geom = geom,
129129
position = position,
130130
show.legend = show.legend,
@@ -141,13 +141,13 @@ stat_bar <- function(mapping = NULL, data = NULL, geom = "bar",
141141
#' @usage NULL
142142
#' @export
143143
#' @include stat-.r
144-
StatBar <- ggproto("StatBar", Stat,
144+
StatCount <- ggproto("StatCount", Stat,
145145
required_aes = "x",
146146
default_aes = aes(y = ..count..),
147147

148148
setup_params = function(data, params) {
149149
if (!is.null(data$y) || !is.null(params$y)) {
150-
stop("stat_bar() must not be used with a y aesthetic.", call. = FALSE)
150+
stop("stat_count() must not be used with a y aesthetic.", call. = FALSE)
151151
}
152152
params
153153
},

man/geom_bar.Rd

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
% Please edit documentation in R/geom-bar.r
33
\name{geom_bar}
44
\alias{geom_bar}
5-
\alias{stat_bar}
5+
\alias{stat_count}
66
\title{Bars, rectangles with bases on x-axis}
77
\usage{
8-
geom_bar(mapping = NULL, data = NULL, stat = "bar", position = "stack",
9-
width = NULL, ..., show.legend = NA, inherit.aes = TRUE)
8+
geom_bar(mapping = NULL, data = NULL, stat = "count",
9+
position = "stack", width = NULL, ..., show.legend = NA,
10+
inherit.aes = TRUE)
1011

11-
stat_bar(mapping = NULL, data = NULL, geom = "bar", position = "stack",
12-
width = NULL, ..., show.legend = NA, inherit.aes = TRUE)
12+
stat_count(mapping = NULL, data = NULL, geom = "bar",
13+
position = "stack", width = NULL, ..., show.legend = NA,
14+
inherit.aes = TRUE)
1315
}
1416
\arguments{
1517
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
@@ -48,13 +50,14 @@ that define both data and aesthetics and shouldn't inherit behaviour from
4850
the default plot specification, e.g. \code{\link{borders}}.}
4951

5052
\item{geom,stat}{Override the default connection between \code{geom_bar} and
51-
\code{stat_bar}.}
53+
\code{stat_count}.}
5254
}
5355
\description{
5456
There are two types of bar charts, determined by what is mapped to bar
55-
height. By default, \code{geom_bar} uses \code{stat = "bar"} which makes the
56-
height of the bar proportion to the number of cases in each group (or
57-
if the \code{weight} aethetic is supplied, the sum of the weights).
57+
height. By default, \code{geom_bar} uses \code{stat = "count"} which makes
58+
the height of the bar proportion to the number of cases in each group (or if
59+
the \code{weight} aethetic is supplied, the sum of the weights). If you want
60+
the heights of the bars to represent values in the data, use
5861
\code{stat="identity"} and map a variable to the \code{y} aesthetic.
5962
}
6063
\details{

man/ggplot2-ggproto.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@
6969
\alias{ScaleDiscreteIdentity}
7070
\alias{ScaleDiscretePosition}
7171
\alias{Stat}
72-
\alias{StatBar}
7372
\alias{StatBin}
7473
\alias{StatBin2d}
7574
\alias{StatBindot}
7675
\alias{StatBinhex}
7776
\alias{StatBoxplot}
7877
\alias{StatContour}
78+
\alias{StatCount}
7979
\alias{StatDensity}
8080
\alias{StatDensity2d}
8181
\alias{StatEcdf}

tests/testthat/test-stat-bin.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
context("stat_bar/stat_bin")
1+
context("stat_bin/stat_count")
22

33
test_that("stat_bin throws error when y aesthetic present", {
44
dat <- data.frame(x = c("a", "b", "c"), y = c(1, 5, 10))
@@ -10,17 +10,17 @@ test_that("stat_bin throws error when y aesthetic present", {
1010
"Unknown parameters: y")
1111
})
1212

13-
test_that("stat_bar throws error when y aesthetic present", {
13+
test_that("stat_count throws error when y aesthetic present", {
1414
dat <- data.frame(x = c("a", "b", "c"), y = c(1, 5, 10))
1515

16-
expect_error(ggplot_build(ggplot(dat, aes(x, y)) + stat_bar()),
16+
expect_error(ggplot_build(ggplot(dat, aes(x, y)) + stat_count()),
1717
"must not be used with a y aesthetic.")
1818

19-
expect_error(p <- ggplot_build(ggplot(dat, aes(x)) + stat_bar(y = 5)),
19+
expect_error(p <- ggplot_build(ggplot(dat, aes(x)) + stat_count(y = 5)),
2020
"Unknown parameters: y")
2121
})
2222

23-
test_that("stat_bar preserves x order for continuous and discrete", {
23+
test_that("stat_count preserves x order for continuous and discrete", {
2424
# x is numeric
2525
b <- ggplot_build(ggplot(mtcars, aes(carb)) + geom_bar())
2626
expect_identical(b$data[[1]]$x, c(1,2,3,4,6,8))

0 commit comments

Comments
 (0)