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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Depends:
R (>= 3.1),
ggplot2 (>= 3.4.4)
Imports:
dplyr (>= 1.0.0),
dplyr (>= 1.1.0),
tidyr (>= 1.3.0),
grDevices,
grid,
Expand Down
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ import(RColorBrewer)
import(ggplot2)
import(utils)
importFrom(dplyr,all_of)
importFrom(dplyr,arrange)
importFrom(dplyr,group_by)
importFrom(dplyr,n)
importFrom(dplyr,pick)
importFrom(dplyr,rename)
importFrom(dplyr,summarise)
importFrom(ggstats,StatCross)
Expand Down Expand Up @@ -170,7 +173,6 @@ importFrom(lifecycle,deprecate_soft)
importFrom(lifecycle,deprecated)
importFrom(magrittr,"%>%")
importFrom(plyr,ddply)
importFrom(plyr,summarize)
importFrom(rlang,"%||%")
importFrom(stats,anova)
importFrom(stats,complete.cases)
Expand Down
25 changes: 13 additions & 12 deletions R/gg-plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,7 @@ ggally_facetbar <- function(data, mapping, ...) {
#' tips, ggplot2::aes(sex, day),
#' floor = 20, ceiling = 50
#' ) + ggplot2::theme(aspect.ratio = 4 / 2))
#' @importFrom dplyr all_of arrange n pick summarise
ggally_ratio <- function(
data,
mapping = ggplot2::aes(!!!stats::setNames(lapply(colnames(data)[1:2], as.name), c("x", "y"))),
Expand All @@ -1329,7 +1330,9 @@ ggally_ratio <- function(
xName <- mapping_string(mapping$x)
yName <- mapping_string(mapping$y)

countData <- plyr::count(data, vars = c(xName, yName))
countData <- data %>%
summarise(freq = n(), .by = all_of(c(xName, yName))) %>%
arrange(pick(c(xName, yName)))

# overwrite names so name clashes don't happen
colnames(countData)[1:2] <- c("x", "y")
Expand Down Expand Up @@ -1756,6 +1759,7 @@ ggally_autopointDiag <- function(data, mapping, ...) {
#' }
#' p_(ggally_summarise_by(tips, mapping = aes(x = total_bill, y = day), text_fn = weighted_sum))
#' }
#' @importFrom dplyr arrange summarise
ggally_summarise_by <- function(
data,
mapping,
Expand All @@ -1767,17 +1771,14 @@ ggally_summarise_by <- function(

horizontal <- is_horizontal(data, mapping)
if (horizontal) {
res <- ddply(
data.frame(
x = eval_data_col(data, mapping$x),
y = eval_data_col(data, mapping$y),
weight = eval_data_col(data, mapping$weight) %||% 1,
stringsAsFactors = FALSE
),
c("y"),
plyr::here(summarize),
label = text_fn(x, weight)
)
res <- data.frame(
x = eval_data_col(data, mapping$x),
y = eval_data_col(data, mapping$y),
weight = eval_data_col(data, mapping$weight) %||% 1,
stringsAsFactors = FALSE
) %>%
summarise(label = text_fn(x, weight), .by = y) %>%
arrange(y)
# keep colour if matching the discrete variable
if (mapping_string(mapping$colour) == mapping_string(mapping$y)) {
col <- as.name("y")
Expand Down
10 changes: 5 additions & 5 deletions R/ggparcoord.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ if (getRversion() >= "2.15.1") {
#' @param title character string denoting the title of the plot
#' @author Jason Crowley, Barret Schloerke, Dianne Cook, Heike Hofmann, Hadley Wickham
#' @return ggplot object that if called, will print
#' @importFrom plyr ddply summarize
#' @importFrom dplyr arrange summarise
#' @importFrom plyr ddply
#' @importFrom stats complete.cases sd median mad lm spline
#' @importFrom tidyr pivot_longer
#' @export
Expand Down Expand Up @@ -512,10 +513,9 @@ ggparcoord <- function(

if (!is.null(shadeBox)) {
# Fix so that if missing = "min10", the box only goes down to the true min
d.sum <- ddply(data.m, c("variable"), summarize,
min = min(value),
max = max(value)
)
d.sum <- data.m %>%
summarise(min = min(value), max = max(value), .by = variable) %>%
arrange(variable)
p <- p + geom_linerange(
data = d.sum, linewidth = I(10), col = shadeBox,
inherit.aes = FALSE,
Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test-zzz_ggpairs.R
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,10 @@ test_that("strip-top and strip-right", {
data(tips)

double_strips <- function(data, mapping, ...) {
dt <- plyr::count(data, c(mapping_string(mapping$x), mapping_string(mapping$y)))
cols <- c(mapping_string(mapping$x), mapping_string(mapping$y))
dt <- data %>%
summarise(freq = n(), .by = all_of(cols)) %>%
arrange(pick(cols))
ggplot(dt, aes(xmin = 0.25, xmax = 0.75, ymin = 1, ymax = freq)) +
geom_rect() +
ggplot2::facet_grid(paste0(mapping_string(mapping$y), " ~ ", mapping_string(mapping$x))) +
Expand Down