|
1 | 1 | #' Create a new layer
|
2 | 2 | #'
|
| 3 | +#' A layer is a combination of data, stat and geom with a potential position |
| 4 | +#' adjustment. Usually layers are created using \code{geom_*} or \code{stat_*} |
| 5 | +#' calls but it can also be created directly using the \code{layer} function. |
| 6 | +#' |
| 7 | +#' @details |
| 8 | +#' The data in a layer can be specified in one of three ways: |
| 9 | +#' |
| 10 | +#' \itemize{ |
| 11 | +#' \item{If the data argument is \code{NULL} (the default) the data is |
| 12 | +#' inherited from the global plot data as specified in the call to |
| 13 | +#' \code{\link{ggplot}}.} |
| 14 | +#' \item{If the data argument is a function, that function is called with the |
| 15 | +#' global data as the only argument and the return value is used as the layer |
| 16 | +#' data. The function must return a data.frame.} |
| 17 | +#' \item{Any other type of value passed to \code{data} will be passed through |
| 18 | +#' \code{\link{fortify}}, and there must thus be a \code{fortify} method |
| 19 | +#' defined for the class of the value. Passing a data.frame is a special case |
| 20 | +#' of this as \code{fortify.data.frame} returns the data.frame untouched.} |
| 21 | +#' } |
| 22 | +#' |
3 | 23 | #' @export
|
4 | 24 | #' @inheritParams geom_point
|
5 | 25 | #' @param geom,stat,position Geom, stat and position adjustment to use in
|
|
16 | 36 | #' layer(geom = "point", stat = "identity", position = "identity",
|
17 | 37 | #' params = list(na.rm = FALSE)
|
18 | 38 | #' )
|
| 39 | +#' |
| 40 | +#' # use a function as data to plot a subset of global data |
| 41 | +#' ggplot(mpg, aes(displ, hwy)) + |
| 42 | +#' layer(geom = "point", stat = "identity", position = "identity", |
| 43 | +#' data = head, params = list(na.rm = FALSE) |
| 44 | +#' ) |
| 45 | +#' |
19 | 46 | layer <- function(geom = NULL, stat = NULL,
|
20 | 47 | data = NULL, mapping = NULL,
|
21 | 48 | position = NULL, params = list(),
|
|
0 commit comments