From c0ce1f8a1372410aaf5fcc1a721fdb4781215b59 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Sat, 13 Apr 2019 14:42:21 +0900 Subject: [PATCH 1/7] Make layer() accept formula notation for data argument --- NAMESPACE | 1 + R/fortify.r | 3 +++ tests/testthat/test-layer.r | 2 ++ 3 files changed, 6 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 847e35f5a6..6d9bfb8214 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/R/fortify.r b/R/fortify.r index 8a8daddf97..0fe6aa70fd 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, ...) rlang::as_function(model) #' @export fortify.grouped_df <- function(model, data, ...) { if (!requireNamespace("dplyr", quietly = TRUE)) { diff --git a/tests/testthat/test-layer.r b/tests/testthat/test-layer.r index f07228adec..401dc92317 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(.)) + expect_equal(l$layer_data(mtcars), head(mtcars)) l <- geom_point(data = nrow) expect_error(l$layer_data(mtcars), "Data function must return a data.frame") }) From dd39a3bfe6678850f98cdf39f2a64f9168fec1a3 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Sat, 13 Apr 2019 14:52:24 +0900 Subject: [PATCH 2/7] Improve the test --- tests/testthat/test-layer.r | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-layer.r b/tests/testthat/test-layer.r index 401dc92317..f97799b9d0 100644 --- a/tests/testthat/test-layer.r +++ b/tests/testthat/test-layer.r @@ -54,8 +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(.)) - 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") }) From 04cb0fcb354a5d9bdb924ffa6273f1fcb0581fa7 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Sat, 13 Apr 2019 14:55:40 +0900 Subject: [PATCH 3/7] Update document about data argument --- R/layer.r | 3 ++- man/borders.Rd | 3 ++- man/geom_abline.Rd | 3 ++- man/geom_bar.Rd | 3 ++- man/geom_bin2d.Rd | 3 ++- man/geom_blank.Rd | 3 ++- man/geom_boxplot.Rd | 3 ++- man/geom_contour.Rd | 3 ++- man/geom_count.Rd | 3 ++- man/geom_density.Rd | 3 ++- man/geom_density_2d.Rd | 3 ++- man/geom_dotplot.Rd | 3 ++- man/geom_errorbarh.Rd | 3 ++- man/geom_hex.Rd | 3 ++- man/geom_histogram.Rd | 3 ++- man/geom_jitter.Rd | 3 ++- man/geom_linerange.Rd | 3 ++- man/geom_map.Rd | 3 ++- man/geom_path.Rd | 3 ++- man/geom_point.Rd | 3 ++- man/geom_polygon.Rd | 3 ++- man/geom_qq.Rd | 3 ++- man/geom_quantile.Rd | 3 ++- man/geom_ribbon.Rd | 3 ++- man/geom_rug.Rd | 3 ++- man/geom_segment.Rd | 3 ++- man/geom_smooth.Rd | 3 ++- man/geom_spoke.Rd | 3 ++- man/geom_text.Rd | 3 ++- man/geom_tile.Rd | 3 ++- man/geom_violin.Rd | 3 ++- man/ggplot2-ggproto.Rd | 2 +- man/ggsf.Rd | 3 ++- man/layer.Rd | 3 ++- man/stat_ecdf.Rd | 3 ++- man/stat_ellipse.Rd | 3 ++- man/stat_function.Rd | 3 ++- man/stat_identity.Rd | 3 ++- man/stat_sf_coordinates.Rd | 3 ++- man/stat_summary.Rd | 3 ++- man/stat_summary_2d.Rd | 3 ++- man/stat_unique.Rd | 3 ++- 42 files changed, 83 insertions(+), 42 deletions(-) diff --git a/R/layer.r b/R/layer.r index b1f4b74925..e1668ee595 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/ggplot2-ggproto.Rd b/man/ggplot2-ggproto.Rd index bad0d955d7..b7afad3c3a 100644 --- a/man/ggplot2-ggproto.Rd +++ b/man/ggplot2-ggproto.Rd @@ -374,7 +374,7 @@ following methods: \item \code{compute_layer(self, data, params, panel)} is called once per layer. \code{panel} is currently an internal data structure, so this method should not be overridden. -\item \code{compute_panel(self, data, params, panel)} is called once per +\item \code{compute_panel(self, data, params, scales)} is called once per panel and should return a modified data frame. \code{data} is a data frame containing the variables named according 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/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} From 3f2d78588ee30529eb6a814024e820a52d42c6d2 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Sat, 13 Apr 2019 14:56:00 +0900 Subject: [PATCH 4/7] Add a NEWS item --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index 3abb02c650..fce239056d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -121,6 +121,9 @@ core developer team. * `sec_axis()` now accepts functions as well as formulas (@yutannihilation, #3031). +* `geom_*()` and `stat_*()` now accepts purrr-style lambda notation + (@yutannihilation, #3138). + # ggplot2 3.1.0 ## Breaking changes From cf3224598d4ea898094e81a45bbea90afc88f981 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Wed, 24 Apr 2019 07:51:40 +0900 Subject: [PATCH 5/7] Remove rlang:: --- R/fortify.r | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/fortify.r b/R/fortify.r index 0fe6aa70fd..cf35a403bf 100644 --- a/R/fortify.r +++ b/R/fortify.r @@ -28,7 +28,7 @@ fortify.NULL <- function(model, data, ...) waiver() fortify.function <- function(model, data, ...) model # accept purrr-style lambda notation #' @export -fortify.formula <- function(model, data, ...) rlang::as_function(model) +fortify.formula <- function(model, data, ...) as_function(model) #' @export fortify.grouped_df <- function(model, data, ...) { if (!requireNamespace("dplyr", quietly = TRUE)) { From bc66eed477ef31da825ddc7ec803ead2b6ca6704 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Wed, 24 Apr 2019 09:51:08 +0900 Subject: [PATCH 6/7] Regenerate docs --- man/layer_sf.Rd | 5 +++-- man/theme.Rd | 13 +++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) 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/theme.Rd b/man/theme.Rd index 2591925f4a..3d5af33dbf 100644 --- a/man/theme.Rd +++ b/man/theme.Rd @@ -251,15 +251,20 @@ p1 + theme( ) # Axes ---------------------------------------------------------------------- +# Change styles of axes texts and lines p1 + theme(axis.line = element_line(size = 3, colour = "grey80")) p1 + theme(axis.text = element_text(colour = "blue")) p1 + theme(axis.ticks = element_line(size = 2)) + +# Change the appearance of the y-axis title +p1 + theme(axis.title.y = element_text(size = rel(1.5), angle = 90)) + +# Make ticks point outwards on y-axis and inwards on x-axis p1 + theme( - axis.ticks.length.y = unit(.25, "cm"), - axis.ticks.length.x = unit(-.25, "cm"), - axis.text.x=element_text(margin=margin(t=.3, unit="cm")) + axis.ticks.length.y = unit(.25, "cm"), + axis.ticks.length.x = unit(-.25, "cm"), + axis.text.x = element_text(margin = margin(t = .3, unit = "cm")) ) -p1 + theme(axis.title.y = element_text(size = rel(1.5), angle = 90)) \donttest{ # Legend -------------------------------------------------------------------- From 3bb89d28e775fb395d3d91019e34425ee14eb12a Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Wed, 24 Apr 2019 10:08:42 +0900 Subject: [PATCH 7/7] Revert man/theme.Rd --- man/theme.Rd | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/man/theme.Rd b/man/theme.Rd index 3d5af33dbf..2591925f4a 100644 --- a/man/theme.Rd +++ b/man/theme.Rd @@ -251,20 +251,15 @@ p1 + theme( ) # Axes ---------------------------------------------------------------------- -# Change styles of axes texts and lines p1 + theme(axis.line = element_line(size = 3, colour = "grey80")) p1 + theme(axis.text = element_text(colour = "blue")) p1 + theme(axis.ticks = element_line(size = 2)) - -# Change the appearance of the y-axis title -p1 + theme(axis.title.y = element_text(size = rel(1.5), angle = 90)) - -# Make ticks point outwards on y-axis and inwards on x-axis p1 + theme( - axis.ticks.length.y = unit(.25, "cm"), - axis.ticks.length.x = unit(-.25, "cm"), - axis.text.x = element_text(margin = margin(t = .3, unit = "cm")) + axis.ticks.length.y = unit(.25, "cm"), + axis.ticks.length.x = unit(-.25, "cm"), + axis.text.x=element_text(margin=margin(t=.3, unit="cm")) ) +p1 + theme(axis.title.y = element_text(size = rel(1.5), angle = 90)) \donttest{ # Legend --------------------------------------------------------------------