diff --git a/DESCRIPTION b/DESCRIPTION index 33a5830..67b15d2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -46,7 +46,7 @@ VignetteBuilder: Config/testthat/edition: 3 Encoding: UTF-8 LazyData: true -RoxygenNote: 7.2.0 +RoxygenNote: 7.2.3 SystemRequirements: pandoc Collate: 'a-legend-draw.R' diff --git a/NAMESPACE b/NAMESPACE index 111ad34..81e9e7e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,9 +12,3 @@ export(geom_line_trace) export(geom_path_trace) export(geom_point_trace) export(geom_step_trace) -import(ggplot2) -importFrom(grid,gpar) -importFrom(grid,grobName) -importFrom(grid,grobTree) -importFrom(grid,pointsGrob) -importFrom(rlang,on_load) diff --git a/R/geom-point-trace.R b/R/geom-point-trace.R index 71886b8..abde22c 100644 --- a/R/geom-point-trace.R +++ b/R/geom-point-trace.R @@ -66,10 +66,10 @@ geom_point_trace <- function(mapping = NULL, data = NULL, stat = "identity", trans_fn <- function(dat, ex, inv = FALSE) { if (inv) { - return(subset(dat, !eval(ex))) + return(subset(dat, !rlang::eval_tidy(ex, dat))) } - subset(dat, eval(ex)) + subset(dat, rlang::eval_tidy(ex, dat)) } create_trace_layers( @@ -81,7 +81,7 @@ geom_point_trace <- function(mapping = NULL, data = NULL, stat = "identity", show.legend = show.legend, inherit.aes = inherit.aes, params = list(na.rm = na.rm, ...), - trace_position = substitute(trace_position), + trace_position = rlang::enquo(trace_position), background_params = background_params, trans_fn = trans_fn, allow_bottom = TRUE @@ -117,7 +117,8 @@ create_trace_layers <- function(mapping, data, stat, geom, position, # If trace_position is 'bottom', create new column and use to override # original group specification. - if (allow_bottom && trace_expr == "bottom") { + if (allow_bottom && identical(rlang::as_label(trace_expr), "\"bottom\"")) { + data <- ggplot2::fortify(~ transform(.x, BOTTOM_TRACE_GROUP = "bottom")) if (is.null(mapping)) { @@ -126,8 +127,8 @@ create_trace_layers <- function(mapping, data, stat, geom, position, mapping$group <- as.name("BOTTOM_TRACE_GROUP") - # If trace_position is not 'all', evaluate expression - } else if (trace_expr != "all") { + # If trace_position is not 'all', evaluate expression + } else if (!identical(rlang::as_label(trace_expr), "\"all\"")) { # If data is not NULL, the user has passed a data.frame, function, or # formula to the geom. Need to fortify this before applying the predicate # passed through trace_position. For a formula fortify will return an diff --git a/R/ggtrace-package.R b/R/ggtrace-package.R index dcb76d1..64c83f7 100644 --- a/R/ggtrace-package.R +++ b/R/ggtrace-package.R @@ -14,12 +14,5 @@ #' #' @name ggtrace #' @docType package -#' @import ggplot2 -#' @importFrom grid -#' gpar -#' pointsGrob -#' grobName -#' grobTree -#' @importFrom rlang on_load #' @keywords internal "_PACKAGE" diff --git a/R/utilities-ggplot2.R b/R/utilities-ggplot2.R index b0a53c1..555c351 100644 --- a/R/utilities-ggplot2.R +++ b/R/utilities-ggplot2.R @@ -134,7 +134,6 @@ modify_list <- function(old, new) { # Info needed for rbind_dfs date/time handling ggtrace_global <- new.env(parent = emptyenv()) -#' @importFrom rlang on_load #' @noRd rlang::on_load({ date <- Sys.Date() diff --git a/man/geom_path_trace.Rd b/man/geom_path_trace.Rd index 29a0363..416eb59 100644 --- a/man/geom_path_trace.Rd +++ b/man/geom_path_trace.Rd @@ -52,10 +52,10 @@ geom_step_trace( ) } \arguments{ -\item{mapping}{Set of aesthetic mappings created by \code{\link[ggplot2:aes]{aes()}} or -\code{\link[ggplot2:aes_]{aes_()}}. If specified and \code{inherit.aes = TRUE} (the -default), it is combined with the default mapping at the top level of the -plot. You must supply \code{mapping} if there is no plot mapping.} +\item{mapping}{Set of aesthetic mappings created by \code{\link[ggplot2:aes]{aes()}}. If specified and +\code{inherit.aes = TRUE} (the default), it is combined with the default mapping +at the top level of the plot. You must supply \code{mapping} if there is no plot +mapping.} \item{data}{The data to be displayed in this layer. There are three options: @@ -73,10 +73,14 @@ 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 -a call to a position adjustment function.} +layer, either as a \code{ggproto} \code{Geom} subclass or as a string naming the +stat stripped of the \code{stat_} prefix (e.g. \code{"count"} rather than +\code{"stat_count"})} + +\item{position}{Position adjustment, either as a string naming the adjustment +(e.g. \code{"jitter"} to use \code{position_jitter}), or the result of a call to a +position adjustment function. Use the latter if you need to change the +settings of the adjustment.} \item{...}{Other arguments passed on to \code{\link[ggplot2:layer]{layer()}}. These are often aesthetics, used to set an aesthetic to a fixed value, like diff --git a/man/geom_point_trace.Rd b/man/geom_point_trace.Rd index f8a7cb6..48b5b1b 100644 --- a/man/geom_point_trace.Rd +++ b/man/geom_point_trace.Rd @@ -18,10 +18,10 @@ geom_point_trace( ) } \arguments{ -\item{mapping}{Set of aesthetic mappings created by \code{\link[ggplot2:aes]{aes()}} or -\code{\link[ggplot2:aes_]{aes_()}}. If specified and \code{inherit.aes = TRUE} (the -default), it is combined with the default mapping at the top level of the -plot. You must supply \code{mapping} if there is no plot mapping.} +\item{mapping}{Set of aesthetic mappings created by \code{\link[ggplot2:aes]{aes()}}. If specified and +\code{inherit.aes = TRUE} (the default), it is combined with the default mapping +at the top level of the plot. You must supply \code{mapping} if there is no plot +mapping.} \item{data}{The data to be displayed in this layer. There are three options: @@ -39,10 +39,14 @@ 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 -a call to a position adjustment function.} +layer, either as a \code{ggproto} \code{Geom} subclass or as a string naming the +stat stripped of the \code{stat_} prefix (e.g. \code{"count"} rather than +\code{"stat_count"})} + +\item{position}{Position adjustment, either as a string naming the adjustment +(e.g. \code{"jitter"} to use \code{position_jitter}), or the result of a call to a +position adjustment function. Use the latter if you need to change the +settings of the adjustment.} \item{...}{Other arguments passed on to \code{\link[ggplot2:layer]{layer()}}. These are often aesthetics, used to set an aesthetic to a fixed value, like