Skip to content

Commit d8f27d4

Browse files
committed
Wrap computed variables in after_stat()
1 parent 2fcee4f commit d8f27d4

36 files changed

+278
-176
lines changed

R/geom-dotplot.r

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@
1818
#'
1919
#' @eval rd_aesthetics("geom", "dotplot")
2020
#' @section Computed variables:
21+
#' These are calculated by the 'stat' part of layers and can be accessed with
22+
#' [delayed evaluation][aes_eval].
2123
#' \describe{
22-
#' \item{x}{center of each bin, if binaxis is "x"}
23-
#' \item{y}{center of each bin, if binaxis is "x"}
24-
#' \item{binwidth}{max width of each bin if method is "dotdensity";
25-
#' width of each bin if method is "histodot"}
26-
#' \item{count}{number of points in bin}
27-
#' \item{ncount}{count, scaled to maximum of 1}
28-
#' \item{density}{density of points in bin, scaled to integrate to 1,
29-
#' if method is "histodot"}
30-
#' \item{ndensity}{density, scaled to maximum of 1, if method is "histodot"}
24+
#' \item{`after_stat(x)`}{center of each bin, if binaxis is "x"}
25+
#' \item{`after_stat(y)`}{center of each bin, if binaxis is "x"}
26+
#' \item{`after_stat(binwidth)`}{max width of each bin if method is
27+
#' "dotdensity"; width of each bin if method is "histodot"}
28+
#' \item{`after_stat(count)`}{number of points in bin}
29+
#' \item{`after_stat(ncount)`}{count, scaled to maximum of 1}
30+
#' \item{`after_stat(density)`}{density of points in bin, scaled to integrate
31+
#' to 1, if method is "histodot"}
32+
#' \item{`after_stat(ndensity)`}{density, scaled to maximum of 1, if method is
33+
#' "histodot"}
3134
#' }
3235
#'
3336
#' @inheritParams layer

R/stat-bin.r

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@
2828
#' @param pad If `TRUE`, adds empty bins at either end of x. This ensures
2929
#' frequency polygons touch 0. Defaults to `FALSE`.
3030
#' @section Computed variables:
31+
#' These are calculated by the 'stat' part of layers and can be accessed with
32+
#' [delayed evaluation][aes_eval].
3133
#' \describe{
32-
#' \item{`count`}{number of points in bin}
33-
#' \item{`density`}{density of points in bin, scaled to integrate to 1}
34-
#' \item{`ncount`}{count, scaled to maximum of 1}
35-
#' \item{`ndensity`}{density, scaled to maximum of 1}
36-
#' \item{`width`}{widths of bins}
34+
#' \item{`after_stat(count)`}{number of points in bin}
35+
#' \item{`after_stat(density)`}{density of points in bin, scaled to integrate
36+
#' to 1}
37+
#' \item{`after_stat(ncount)`}{count, scaled to maximum of 1}
38+
#' \item{`after_stat(ndensity)`}{density, scaled to maximum of 1}
39+
#' \item{`after_stat(width)`}{widths of bins}
3740
#' }
3841
#'
3942
#' @section Dropped variables:

R/stat-bin2d.r

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
#' @export
77
#' @rdname geom_bin_2d
88
#' @section Computed variables:
9+
#' These are calculated by the 'stat' part of layers and can be accessed with
10+
#' [delayed evaluation][aes_eval].
911
#' \describe{
10-
#' \item{count}{number of points in bin}
11-
#' \item{density}{density of points in bin, scaled to integrate to 1}
12-
#' \item{ncount}{count, scaled to maximum of 1}
13-
#' \item{ndensity}{density, scaled to maximum of 1}
12+
#' \item{`after_stat(count)`}{number of points in bin}
13+
#' \item{`after_stat(density)`}{density of points in bin, scaled to integrate
14+
#' to 1}
15+
#' \item{`after_stat(ncount)`}{count, scaled to maximum of 1}
16+
#' \item{`after_stat(ndensity)`}{density, scaled to maximum of 1}
1417
#' }
1518
stat_bin_2d <- function(mapping = NULL, data = NULL,
1619
geom = "tile", position = "identity",

R/stat-binhex.r

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
#' @rdname geom_hex
33
#' @inheritParams stat_bin_2d
44
#' @section Computed variables:
5+
#' These are calculated by the 'stat' part of layers and can be accessed with
6+
#' [delayed evaluation][aes_eval].
57
#' \describe{
6-
#' \item{count}{number of points in bin}
7-
#' \item{density}{density of points in bin, scaled to integrate to 1}
8-
#' \item{ncount}{count, scaled to maximum of 1}
9-
#' \item{ndensity}{density, scaled to maximum of 1}
8+
#' \item{`after_stat(count)`}{number of points in bin}
9+
#' \item{`after_stat(density)`}{density of points in bin, scaled to integrate
10+
#' to 1}
11+
#' \item{`after_stat(ncount)`}{count, scaled to maximum of 1}
12+
#' \item{`after_stat(ndensity)`}{density, scaled to maximum of 1}
1013
#' }
1114
stat_bin_hex <- function(mapping = NULL, data = NULL,
1215
geom = "hex", position = "identity",

R/stat-boxplot.r

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,25 @@
22
#' @param coef Length of the whiskers as multiple of IQR. Defaults to 1.5.
33
#' @inheritParams stat_identity
44
#' @section Computed variables:
5-
#' `stat_boxplot()` provides the following variables, some of which depend on the orientation:
5+
#' These are calculated by the 'stat' part of layers and can be accessed with
6+
#' [delayed evaluation][aes_eval]. `stat_boxplot()` provides the following
7+
#' variables, some of which depend on the orientation:
68
#' \describe{
7-
#' \item{width}{width of boxplot}
8-
#' \item{ymin *or* xmin}{lower whisker = smallest observation greater than or equal to lower hinge - 1.5 * IQR}
9-
#' \item{lower *or* xlower}{lower hinge, 25% quantile}
10-
#' \item{notchlower}{lower edge of notch = median - 1.58 * IQR / sqrt(n)}
11-
#' \item{middle *or* xmiddle}{median, 50% quantile}
12-
#' \item{notchupper}{upper edge of notch = median + 1.58 * IQR / sqrt(n)}
13-
#' \item{upper *or* xupper}{upper hinge, 75% quantile}
14-
#' \item{ymax *or* xmax}{upper whisker = largest observation less than or equal to upper hinge + 1.5 * IQR}
9+
#' \item{`after_stat(width)`}{width of boxplot}
10+
#' \item{`after_stat(ymin)` *or* `after_stat(xmin)`}{lower whisker = smallest
11+
#' observation greater than or equal to lower hinge - 1.5 * IQR}
12+
#' \item{`after_stat(lower)` *or* `after_stat(xlower)`}{lower hinge, 25%
13+
#' quantile}
14+
#' \item{`after_stat(notchlower)`}{lower edge of notch =
15+
#' median - 1.58 * IQR / sqrt(n)}
16+
#' \item{`after_stat(middle)` *or* `after_stat(xmiddle)`}{median,
17+
#' 50% quantile}
18+
#' \item{`after_stat(notchupper)`}{upper edge of notch =
19+
#' median + 1.58 * IQR / sqrt(n)}
20+
#' \item{`after_stat(upper)` *or* `after_stat(xupper)`}{upper hinge, 75%
21+
#' quantile}
22+
#' \item{`after_stat(ymax)` *or* `after_stat(xmax)`}{upper whisker = largest
23+
#' observation less than or equal to upper hinge + 1.5 * IQR}
1524
#' }
1625
#' @export
1726
stat_boxplot <- function(mapping = NULL, data = NULL,

R/stat-contour.r

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44
#' @eval rd_aesthetics("stat", "contour")
55
#' @eval rd_aesthetics("stat", "contour_filled")
66
#' @section Computed variables:
7-
#' The computed variables differ somewhat for contour lines (computed by
8-
#' `stat_contour()`) and contour bands (filled contours, computed by `stat_contour_filled()`).
9-
#' The variables `nlevel` and `piece` are available for both, whereas `level_low`, `level_high`,
10-
#' and `level_mid` are only available for bands. The variable `level` is a numeric or a factor
11-
#' depending on whether lines or bands are calculated.
7+
#' These are calculated by the 'stat' part of layers and can be accessed with
8+
#' [delayed evaluation][aes_eval]. The computed variables differ somewhat for
9+
#' contour lines (computed by `stat_contour()`) and contour bands (filled
10+
#' contours, computed by `stat_contour_filled()`). The variables `nlevel` and
11+
#' `piece` are available for both, whereas `level_low`, `level_high`, and
12+
#' `level_mid` are only available for bands. The variable `level` is a numeric
13+
#' or a factor depending on whether lines or bands are calculated.
1214
#' \describe{
13-
#' \item{`level`}{Height of contour. For contour lines, this is numeric vector that
14-
#' represents bin boundaries. For contour bands, this is an ordered factor that
15-
#' represents bin ranges.}
16-
#' \item{`level_low`, `level_high`, `level_mid`}{(contour bands only) Lower and upper
17-
#' bin boundaries for each band, as well the mid point between the boundaries.}
18-
#' \item{`nlevel`}{Height of contour, scaled to maximum of 1.}
19-
#' \item{`piece`}{Contour piece (an integer).}
15+
#' \item{`after_stat(level)`}{Height of contour. For contour lines, this is
16+
#' numeric vector that represents bin boundaries. For contour bands, this is
17+
#' an ordered factor that represents bin ranges.}
18+
#' \item{`after_stat(level_low)`, `after_stat(level_high)`,
19+
#' `after_stat(level_mid)`}{(contour bands only) Lower and upper bin
20+
#' boundaries for each band, as well the mid point between the boundaries.}
21+
#' \item{`after_stat(nlevel)`}{Height of contour, scaled to maximum of 1.}
22+
#' \item{`after_stat(piece)`}{Contour piece (an integer).}
2023
#' }
2124
#'
2225
#' @section Dropped variables:

R/stat-count.r

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#' @section Computed variables:
2+
#' These are calculated by the 'stat' part of layers and can be accessed with
3+
#' [delayed evaluation][aes_eval].
24
#' \describe{
3-
#' \item{count}{number of points in bin}
4-
#' \item{prop}{groupwise proportion}
5+
#' \item{`after_stat(count)`}{number of points in bin}
6+
#' \item{`after_stat(prop)`}{groupwise proportion}
57
#' }
68
#' @seealso [stat_bin()], which bins data in ranges and counts the
79
#' cases in each range. It differs from `stat_count()`, which counts the

R/stat-density-2d.r

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414
#' using the a bandwidth estimator. For example, `adjust = 1/2` means
1515
#' use half of the default bandwidth.
1616
#' @section Computed variables:
17-
#' `stat_density_2d()` and `stat_density_2d_filled()` compute different
18-
#' variables depending on whether contouring is turned on or off. With
19-
#' contouring off (`contour = FALSE`), both stats behave the same, and the
20-
#' following variables are provided:
17+
#' These are calculated by the 'stat' part of layers and can be accessed with
18+
#' [delayed evaluation][aes_eval]. `stat_density_2d()` and
19+
#' `stat_density_2d_filled()` compute different variables depending on whether
20+
#' contouring is turned on or off. With contouring off (`contour = FALSE`), both
21+
#' stats behave the same, and the following variables are provided:
2122
#' \describe{
22-
#' \item{`density`}{The density estimate.}
23-
#' \item{`ndensity`}{Density estimate, scaled to a maximum of 1.}
24-
#' \item{`count`}{Density estimate * number of observations in group.}
25-
#' \item{`n`}{Number of observations in each group.}
23+
#' \item{`after_stat(density)`}{The density estimate.}
24+
#' \item{`after_stat(ndensity)`}{Density estimate, scaled to a maximum of 1.}
25+
#' \item{`after_stat(count)`}{Density estimate * number of observations in
26+
#' group.}
27+
#' \item{`after_stat(n)`}{Number of observations in each group.}
2628
#' }
2729
#'
2830
#' With contouring on (`contour = TRUE`), either [stat_contour()] or

R/stat-density.r

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
#' reflecting tails outside `bounds` around their closest edge. Data points
2222
#' outside of bounds are removed with a warning.
2323
#' @section Computed variables:
24+
#' These are calculated by the 'stat' part of layers and can be accessed with
25+
#' [delayed evaluation][aes_eval].
2426
#' \describe{
25-
#' \item{density}{density estimate}
26-
#' \item{count}{density * number of points - useful for stacked density
27-
#' plots}
28-
#' \item{scaled}{density estimate, scaled to maximum of 1}
29-
#' \item{n}{number of points}
30-
#' \item{ndensity}{alias for `scaled`, to mirror the syntax of
27+
#' \item{`after_stat(density)`}{density estimate}
28+
#' \item{`after_stat(count)`}{density * number of points - useful for stacked
29+
#' density plots}
30+
#' \item{`after_stat(scaled)`}{density estimate, scaled to maximum of 1}
31+
#' \item{`after_stat(n)`}{number of points}
32+
#' \item{`after_stat(ndensity)`}{alias for `scaled`, to mirror the syntax of
3133
#' [`stat_bin()`]}
3234
#' }
3335
#' @export

R/stat-ecdf.r

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
#' @param pad If `TRUE`, pad the ecdf with additional points (-Inf, 0)
2222
#' and (Inf, 1)
2323
#' @section Computed variables:
24+
#' These are calculated by the 'stat' part of layers and can be accessed with
25+
#' [delayed evaluation][aes_eval].
2426
#' \describe{
25-
#' \item{y}{cumulative density corresponding x}
27+
#' \item{`after_stat(y)`}{cumulative density corresponding x}
2628
#' }
2729
#' @export
2830
#' @examples

0 commit comments

Comments
 (0)