Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 7 additions & 12 deletions R/deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions R/gg-plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down