diff --git a/NAMESPACE b/NAMESPACE index c2cb46bfd..48e1aeb58 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -138,6 +138,7 @@ import(utils) importFrom(dplyr,all_of) importFrom(dplyr,arrange) importFrom(dplyr,group_by) +importFrom(dplyr,mutate) importFrom(dplyr,n) importFrom(dplyr,pick) importFrom(dplyr,rename) diff --git a/R/deprecated.R b/R/deprecated.R index c81a507bf..05864301e 100644 --- a/R/deprecated.R +++ b/R/deprecated.R @@ -37,6 +37,7 @@ v1_ggmatrix_theme <- function() { #' @param displayGrid if TRUE, display aligned panel gridlines #' @param ... other arguments being supplied to geom_text #' @author Barret Schloerke +#' @importFrom dplyr %>% arrange mutate summarise #' @importFrom stats complete.cases cor #' @seealso \code{\link{ggally_cor}} #' @export @@ -103,7 +104,7 @@ ggally_cor_v1_5 <- function( } cor_fn <- function(x, y) { - # also do ddply below if fn is altered + # also do summarise below if fn is altered cor(x, y, method = method, use = use) } @@ -195,21 +196,15 @@ ggally_cor_v1_5 <- function( !is.null(colorData) && !inherits(colorData, "AsIs") ) { - cord <- ddply( - data.frame(x = xData, y = yData, color = colorData), - "color", - function(dt) { - cor_fn(dt$x, dt$y) - } - ) - colnames(cord)[2] <- "correlation" - - cord$correlation <- signif(as.numeric(cord$correlation), 3) + cord <- data.frame(x = xData, y = yData, color = colorData) %>% + summarise(correlation = cor_fn(x, y), .by = color) %>% + arrange(color) %>% + mutate(correlation = signif(as.numeric(correlation), 3L)) # put in correct order lev <- levels(as.factor(colorData)) ord <- rep(-1, nrow(cord)) - for (i in 1:nrow(cord)) { + for (i in seq_len(nrow(cord))) { for (j in seq_along(lev)) { if (identical(as.character(cord$color[i]), as.character(lev[j]))) { ord[i] <- j diff --git a/R/gg-plots.R b/R/gg-plots.R index 7912d462e..feaf34298 100644 --- a/R/gg-plots.R +++ b/R/gg-plots.R @@ -384,6 +384,7 @@ ggally_cor <- function( #' @param align_percent relative align position of the text. When \code{title_hjust = 0.5} and \code{group_hjust = 0.5}, this should not be needed to be set. #' @param title_hjust,group_hjust \code{hjust} sent to \code{\link[ggplot2]{geom_text}()} for the title and group values respectively. Any \code{hjust} value supplied in \code{title_args} or \code{group_args} will take precedence. #' @seealso \code{\link{ggally_cor}} +#' @importFrom dplyr %>% arrange summarize #' @export ggally_statistic <- function( data, @@ -477,19 +478,14 @@ ggally_statistic <- function( # if there is a color grouping... if (!is.null(colorData) && !inherits(colorData, "AsIs")) { - cord <- ddply( - data.frame(x = xData, y = yData, color = colorData), - "color", - function(dt) { - text_fn(dt$x, dt$y) - } - ) - colnames(cord)[2] <- "text" + cord <- data.frame(x = xData, y = yData, color = colorData) %>% + summarise(text = text_fn(x, y), .by = color) %>% + arrange(color) # put in correct order lev <- levels(as.factor(colorData)) ord <- rep(-1, nrow(cord)) - for (i in 1:nrow(cord)) { + for (i in seq_len(nrow(cord))) { for (j in seq_along(lev)) { if (identical(as.character(cord$color[i]), as.character(lev[j]))) { ord[i] <- j