Skip to content

Commit 0e75964

Browse files
committed
document
1 parent 8d5d3f6 commit 0e75964

File tree

5 files changed

+192
-5
lines changed

5 files changed

+192
-5
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ Collate:
247247
'stat-bindot.R'
248248
'stat-binhex.R'
249249
'stat-boxplot.R'
250+
'stat-chain.R'
250251
'stat-contour.R'
251252
'stat-count.R'
252253
'stat-density-2d.R'

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ export(StatBin2d)
257257
export(StatBindot)
258258
export(StatBinhex)
259259
export(StatBoxplot)
260+
export(StatChain)
260261
export(StatContour)
261262
export(StatContourFilled)
262263
export(StatCount)
@@ -684,6 +685,7 @@ export(stat_bin_2d)
684685
export(stat_bin_hex)
685686
export(stat_binhex)
686687
export(stat_boxplot)
688+
export(stat_chain)
687689
export(stat_contour)
688690
export(stat_contour_filled)
689691
export(stat_count)

R/stat-chain.R

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
#' Chain statistic computation
2+
#'
3+
#' This statistic layer can take multiple stats and chain these together
4+
#' to transform the data in a series of computations.
5+
#'
6+
#' @inheritParams layer
7+
#' @inheritParams geom_point
8+
#' @param stats A character vector or list of statistical transformations to use
9+
#' for this layer. Every element needs to be one of the following:
10+
#' * A `Stat` ggproto subclass, for example `StatCount`
11+
#' * A string naming the stat. To give the stat as a string, strip the
12+
#' function name of the `stat_` prefix. For example, to use `stat_count()`,
13+
#' give the stat as `"count"`.
14+
#' @param stat.params A list of parameters parallel to the `stats` argument.
15+
#' Use `NULL` elements to declare no parameters.
16+
#' @param redirect A list of mappings parallel to the `stats` argument that
17+
#' are evaluated after the stat has been computed.
18+
#'
19+
#' @export
20+
#'
21+
#' @examples
22+
#' p <- ggplot(mpg, aes(displ, colour = drv))
23+
#' # Binning unique observations
24+
#' p + stat_chain(stats = c("unique", "bin"))
25+
#' # Controlling parameters
26+
#' p + stat_chain(
27+
#' stats = c("unique", "bin"),
28+
#' stat.params = list(NULL, list(bins = 10))
29+
#' )
30+
#' # Evaluate expressions after computing stats
31+
#' p + stat_chain(
32+
#' stats = c("unique", "bin"),
33+
#' redirect = list(aes(x = x + 1), aes(y = density))
34+
#' )
135
stat_chain <- function(
236
mapping = NULL,
337
data = NULL,
@@ -29,6 +63,10 @@ stat_chain <- function(
2963
)
3064
}
3165

66+
#' @rdname ggplot2-ggproto
67+
#' @format NULL
68+
#' @usage NULL
69+
#' @export
3270
StatChain <- ggproto(
3371
"StatChain", Stat,
3472

man/ggplot2-ggproto.Rd

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

man/stat_chain.Rd

Lines changed: 145 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)