diff --git a/NAMESPACE b/NAMESPACE index 652c30c465..246ef69e2c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -32,6 +32,7 @@ S3method(fortify,cld) S3method(fortify,confint.glht) S3method(fortify,data.frame) S3method(fortify,default) +S3method(fortify,formula) S3method(fortify,glht) S3method(fortify,grouped_df) S3method(fortify,lm) diff --git a/NEWS.md b/NEWS.md index 4a4d8dc7ac..aeca5339c9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -138,6 +138,9 @@ core developer team. now renamed to always match the ones of `Stat$compute_layer()` and `Position$compute_layer()` (@yutannihilation, #3202). +* `geom_*()` and `stat_*()` now accepts purrr-style lambda notation + (@yutannihilation, #3138). + # ggplot2 3.1.0 ## Breaking changes diff --git a/R/fortify.r b/R/fortify.r index 8a8daddf97..cf35a403bf 100644 --- a/R/fortify.r +++ b/R/fortify.r @@ -26,6 +26,9 @@ fortify.tbl <- function(model, data, ...) { fortify.NULL <- function(model, data, ...) waiver() #' @export fortify.function <- function(model, data, ...) model +# accept purrr-style lambda notation +#' @export +fortify.formula <- function(model, data, ...) as_function(model) #' @export fortify.grouped_df <- function(model, data, ...) { if (!requireNamespace("dplyr", quietly = TRUE)) { diff --git a/R/layer.r b/R/layer.r index 72b03609ef..34c509b91e 100644 --- a/R/layer.r +++ b/R/layer.r @@ -22,7 +22,8 @@ #' #' A `function` will be called with a single argument, #' the plot data. The return value must be a `data.frame`, and -#' will be used as the layer data. +#' will be used as the layer data. A `function` can be created +#' from a `formula` (e.g. `~ head(.x, 10)`). #' @param geom The geometric object to use display the data #' @param stat The statistical transformation to use on the data for this #' layer, as a string. diff --git a/man/borders.Rd b/man/borders.Rd index eff17e1e2b..076d3b9df6 100644 --- a/man/borders.Rd +++ b/man/borders.Rd @@ -41,7 +41,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} \item{position}{Position adjustment, either as a string, or the result of diff --git a/man/geom_abline.Rd b/man/geom_abline.Rd index e5e23cf1d7..cc40e3c6f0 100644 --- a/man/geom_abline.Rd +++ b/man/geom_abline.Rd @@ -30,7 +30,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{...}{Other arguments passed on to \code{\link[=layer]{layer()}}. These are often aesthetics, used to set an aesthetic to a fixed value, like diff --git a/man/geom_bar.Rd b/man/geom_bar.Rd index e0f914558a..d6245de4a9 100644 --- a/man/geom_bar.Rd +++ b/man/geom_bar.Rd @@ -36,7 +36,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{position}{Position adjustment, either as a string, or the result of a call to a position adjustment function.} diff --git a/man/geom_bin2d.Rd b/man/geom_bin2d.Rd index d004cfdcd8..1f879f8cfe 100644 --- a/man/geom_bin2d.Rd +++ b/man/geom_bin2d.Rd @@ -32,7 +32,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{position}{Position adjustment, either as a string, or the result of a call to a position adjustment function.} diff --git a/man/geom_blank.Rd b/man/geom_blank.Rd index 6c1a0963ca..ce4101334f 100644 --- a/man/geom_blank.Rd +++ b/man/geom_blank.Rd @@ -25,7 +25,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} diff --git a/man/geom_boxplot.Rd b/man/geom_boxplot.Rd index d42d4d5789..19b56385ec 100644 --- a/man/geom_boxplot.Rd +++ b/man/geom_boxplot.Rd @@ -34,7 +34,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{position}{Position adjustment, either as a string, or the result of a call to a position adjustment function.} diff --git a/man/geom_contour.Rd b/man/geom_contour.Rd index 2fa02256ab..6ba7b1cdb1 100644 --- a/man/geom_contour.Rd +++ b/man/geom_contour.Rd @@ -32,7 +32,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} diff --git a/man/geom_count.Rd b/man/geom_count.Rd index e2421f60a5..4cd241c28d 100644 --- a/man/geom_count.Rd +++ b/man/geom_count.Rd @@ -31,7 +31,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{position}{Position adjustment, either as a string, or the result of a call to a position adjustment function.} diff --git a/man/geom_density.Rd b/man/geom_density.Rd index 72d25b8661..3ccef5179d 100644 --- a/man/geom_density.Rd +++ b/man/geom_density.Rd @@ -32,7 +32,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{position}{Position adjustment, either as a string, or the result of a call to a position adjustment function.} diff --git a/man/geom_density_2d.Rd b/man/geom_density_2d.Rd index dead4ecd28..c649a29884 100644 --- a/man/geom_density_2d.Rd +++ b/man/geom_density_2d.Rd @@ -34,7 +34,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{position}{Position adjustment, either as a string, or the result of a call to a position adjustment function.} diff --git a/man/geom_dotplot.Rd b/man/geom_dotplot.Rd index 0d972e5810..31c9b50cba 100644 --- a/man/geom_dotplot.Rd +++ b/man/geom_dotplot.Rd @@ -29,7 +29,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{position}{Position adjustment, either as a string, or the result of a call to a position adjustment function.} diff --git a/man/geom_errorbarh.Rd b/man/geom_errorbarh.Rd index 7e11334c9c..a266a55017 100644 --- a/man/geom_errorbarh.Rd +++ b/man/geom_errorbarh.Rd @@ -26,7 +26,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} diff --git a/man/geom_hex.Rd b/man/geom_hex.Rd index 602693864c..bbd29d982a 100644 --- a/man/geom_hex.Rd +++ b/man/geom_hex.Rd @@ -32,7 +32,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{position}{Position adjustment, either as a string, or the result of a call to a position adjustment function.} diff --git a/man/geom_histogram.Rd b/man/geom_histogram.Rd index 72c14ad4ec..99189ee2a9 100644 --- a/man/geom_histogram.Rd +++ b/man/geom_histogram.Rd @@ -39,7 +39,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{position}{Position adjustment, either as a string, or the result of a call to a position adjustment function.} diff --git a/man/geom_jitter.Rd b/man/geom_jitter.Rd index 2851418a3a..3f999f4976 100644 --- a/man/geom_jitter.Rd +++ b/man/geom_jitter.Rd @@ -26,7 +26,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} diff --git a/man/geom_linerange.Rd b/man/geom_linerange.Rd index bbec0fbba5..fcb57f367f 100644 --- a/man/geom_linerange.Rd +++ b/man/geom_linerange.Rd @@ -42,7 +42,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} diff --git a/man/geom_map.Rd b/man/geom_map.Rd index 07eb885020..adde0e8289 100644 --- a/man/geom_map.Rd +++ b/man/geom_map.Rd @@ -25,7 +25,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} diff --git a/man/geom_path.Rd b/man/geom_path.Rd index d2c735aed0..3269ac29ef 100644 --- a/man/geom_path.Rd +++ b/man/geom_path.Rd @@ -37,7 +37,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} diff --git a/man/geom_point.Rd b/man/geom_point.Rd index 2e494ab83d..3975805faf 100644 --- a/man/geom_point.Rd +++ b/man/geom_point.Rd @@ -26,7 +26,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} diff --git a/man/geom_polygon.Rd b/man/geom_polygon.Rd index cdf7b7a527..54409c8dde 100644 --- a/man/geom_polygon.Rd +++ b/man/geom_polygon.Rd @@ -26,7 +26,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} diff --git a/man/geom_qq.Rd b/man/geom_qq.Rd index 32505df89d..ea9c743f88 100644 --- a/man/geom_qq.Rd +++ b/man/geom_qq.Rd @@ -45,7 +45,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{geom}{The geometric object to use display the data} diff --git a/man/geom_quantile.Rd b/man/geom_quantile.Rd index fad9714114..820f9485fd 100644 --- a/man/geom_quantile.Rd +++ b/man/geom_quantile.Rd @@ -33,7 +33,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{position}{Position adjustment, either as a string, or the result of a call to a position adjustment function.} diff --git a/man/geom_ribbon.Rd b/man/geom_ribbon.Rd index 34a7cd700d..af2288135e 100644 --- a/man/geom_ribbon.Rd +++ b/man/geom_ribbon.Rd @@ -31,7 +31,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} diff --git a/man/geom_rug.Rd b/man/geom_rug.Rd index cf96cbf0d0..71937e8da9 100644 --- a/man/geom_rug.Rd +++ b/man/geom_rug.Rd @@ -27,7 +27,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} diff --git a/man/geom_segment.Rd b/man/geom_segment.Rd index 7146d36ac9..76124f5f7e 100644 --- a/man/geom_segment.Rd +++ b/man/geom_segment.Rd @@ -33,7 +33,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} diff --git a/man/geom_smooth.Rd b/man/geom_smooth.Rd index 215eb2d8cd..b1e0f69682 100644 --- a/man/geom_smooth.Rd +++ b/man/geom_smooth.Rd @@ -33,7 +33,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{position}{Position adjustment, either as a string, or the result of a call to a position adjustment function.} diff --git a/man/geom_spoke.Rd b/man/geom_spoke.Rd index 1bac8b7459..fe40a4981d 100644 --- a/man/geom_spoke.Rd +++ b/man/geom_spoke.Rd @@ -27,7 +27,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} diff --git a/man/geom_text.Rd b/man/geom_text.Rd index beb9a6d5d1..c43e79da98 100644 --- a/man/geom_text.Rd +++ b/man/geom_text.Rd @@ -34,7 +34,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} diff --git a/man/geom_tile.Rd b/man/geom_tile.Rd index e350939914..ad8ff55ec6 100644 --- a/man/geom_tile.Rd +++ b/man/geom_tile.Rd @@ -37,7 +37,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} diff --git a/man/geom_violin.Rd b/man/geom_violin.Rd index 0cecb3b442..247949f78d 100644 --- a/man/geom_violin.Rd +++ b/man/geom_violin.Rd @@ -33,7 +33,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{position}{Position adjustment, either as a string, or the result of a call to a position adjustment function.} diff --git a/man/ggsf.Rd b/man/ggsf.Rd index 6662e7d4f7..3b16abc7e2 100644 --- a/man/ggsf.Rd +++ b/man/ggsf.Rd @@ -108,7 +108,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{stat}{The statistical transformation to use on the data for this layer, as a string.} diff --git a/man/layer.Rd b/man/layer.Rd index c22b09104d..b002d45d14 100644 --- a/man/layer.Rd +++ b/man/layer.Rd @@ -27,7 +27,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{mapping}{Set of aesthetic mappings created by \code{\link[=aes]{aes()}} or \code{\link[=aes_]{aes_()}}. If specified and \code{inherit.aes = TRUE} (the diff --git a/man/layer_sf.Rd b/man/layer_sf.Rd index 2ca5043fa6..7ede6671f8 100644 --- a/man/layer_sf.Rd +++ b/man/layer_sf.Rd @@ -26,7 +26,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{mapping}{Set of aesthetic mappings created by \code{\link[=aes]{aes()}} or \code{\link[=aes_]{aes_()}}. If specified and \code{inherit.aes = TRUE} (the @@ -61,6 +62,6 @@ display.} The \code{layer_sf()} function is a variant of \code{\link[=layer]{layer()}} meant to be used by extension developers who are writing new sf-based geoms or stats. The sf layer checks whether the data contains a geometry column, and -if one is found it is automatically mapped to the \code{geomtry} aesthetic. +if one is found it is automatically mapped to the \code{geometry} aesthetic. } \keyword{internal} diff --git a/man/stat_ecdf.Rd b/man/stat_ecdf.Rd index 02a3dab8af..6f96c6c2a9 100644 --- a/man/stat_ecdf.Rd +++ b/man/stat_ecdf.Rd @@ -26,7 +26,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{geom}{The geometric object to use display the data} diff --git a/man/stat_ellipse.Rd b/man/stat_ellipse.Rd index 199ce2e66d..aa1a6cd163 100644 --- a/man/stat_ellipse.Rd +++ b/man/stat_ellipse.Rd @@ -27,7 +27,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{geom}{The geometric object to use display the data} diff --git a/man/stat_function.Rd b/man/stat_function.Rd index 096922e77e..38793a0577 100644 --- a/man/stat_function.Rd +++ b/man/stat_function.Rd @@ -27,7 +27,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{geom}{The geometric object to use display the data} diff --git a/man/stat_identity.Rd b/man/stat_identity.Rd index 46bcc533ea..3628b28a0a 100644 --- a/man/stat_identity.Rd +++ b/man/stat_identity.Rd @@ -25,7 +25,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{geom}{The geometric object to use display the data} diff --git a/man/stat_sf_coordinates.Rd b/man/stat_sf_coordinates.Rd index e658ffefb0..b47bf64e82 100644 --- a/man/stat_sf_coordinates.Rd +++ b/man/stat_sf_coordinates.Rd @@ -28,7 +28,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{geom}{The geometric object to use display the data} diff --git a/man/stat_summary.Rd b/man/stat_summary.Rd index 020cd35600..b1facb5f16 100644 --- a/man/stat_summary.Rd +++ b/man/stat_summary.Rd @@ -34,7 +34,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{geom}{Use to override the default connection between \code{geom_histogram()}/\code{geom_freqpoly()} and \code{stat_bin()}.} diff --git a/man/stat_summary_2d.Rd b/man/stat_summary_2d.Rd index d8531db9df..51a90038c9 100644 --- a/man/stat_summary_2d.Rd +++ b/man/stat_summary_2d.Rd @@ -34,7 +34,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{geom}{The geometric object to use display the data} diff --git a/man/stat_unique.Rd b/man/stat_unique.Rd index a1b276fcec..a646b4fd77 100644 --- a/man/stat_unique.Rd +++ b/man/stat_unique.Rd @@ -26,7 +26,8 @@ data. All objects will be fortified to produce a data frame. See A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and -will be used as the layer data.} +will be used as the layer data. A \code{function} can be created +from a \code{formula} (e.g. \code{~ head(.x, 10)}).} \item{geom}{The geometric object to use display the data} diff --git a/tests/testthat/test-layer.r b/tests/testthat/test-layer.r index f07228adec..f97799b9d0 100644 --- a/tests/testthat/test-layer.r +++ b/tests/testthat/test-layer.r @@ -54,6 +54,8 @@ test_that("layer_data returns a data.frame", { expect_equal(l$layer_data(mtcars), head(mtcars)) l <- geom_point(data = head) expect_equal(l$layer_data(mtcars), head(mtcars)) + l <- geom_point(data = ~ head(., 10)) + expect_equal(l$layer_data(mtcars), head(mtcars, 10)) l <- geom_point(data = nrow) expect_error(l$layer_data(mtcars), "Data function must return a data.frame") })