Skip to content

Commit

Permalink
Follow recommended practice for using ggplot2::aes() in packages
Browse files Browse the repository at this point in the history
  • Loading branch information
jdblischak committed Feb 9, 2024
1 parent ef73234 commit 617338a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: gsDesign
Version: 3.6.0.3
Version: 3.6.0.4
Title: Group Sequential Design
Authors@R: person(given = "Keaven", family = "Anderson", email =
"keaven_anderson@merck.com", role = c('aut','cre'))
Expand All @@ -18,7 +18,7 @@ Depends:
R (>= 3.5.0)
Imports:
dplyr (>= 1.1.0),
ggplot2 (>= 0.9.2),
ggplot2 (>= 3.1.1),
graphics,
gt,
magrittr,
Expand Down
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ importFrom(r2rtf,rtf_encode)
importFrom(r2rtf,rtf_footnote)
importFrom(r2rtf,rtf_title)
importFrom(r2rtf,write_rtf)
importFrom(rlang,"!!")
importFrom(rlang,sym)
importFrom(rlang,.data)
importFrom(stats,dnorm)
importFrom(stats,nlminb)
importFrom(stats,pbeta)
Expand Down
10 changes: 5 additions & 5 deletions R/gsBinomialExact.R
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,18 @@ binomialSPRT <- function(p0 = .05, p1 = .25, alpha = .1, beta = .15, minn = 10,
#' @rdname gsBinomialExact
#' @export
#' @importFrom ggplot2 ggplot aes geom_line ylab geom_point xlab
#' @importFrom rlang !! sym
#' @importFrom rlang .data
# plot.gsBinomialExact function [sinew] ----
plot.gsBinomialExact <- function(x, plottype = 1, ...) {
if (plottype == 6) {
theta <- (max(x$theta) - min(x$theta)) * (0:50) / 50 + min(x$theta)
y <- gsBinomialExact(k = x$k, theta = theta, n.I = x$n.I, a = x$lower$bound, b = x$upper$bound)
xx <- data.frame(p = theta, EN = y$en)
p <- ggplot2::ggplot(data = xx, ggplot2::aes(x = p, y = !!rlang::sym('EN'))) + ggplot2::geom_line() + ggplot2::ylab("Expected sample size")
p <- ggplot2::ggplot(data = xx, ggplot2::aes(x = p, y = .data$EN)) + ggplot2::geom_line() + ggplot2::ylab("Expected sample size")
} else if (plottype == 3) {
xx <- data.frame(N = x$n.I, p = x$upper$bound / x$n.I, Bound = "Upper")
xx <- rbind(xx, data.frame(N = x$n.I, p = x$lower$bound / x$n.I, Bound = "Lower"))
p <- ggplot2::ggplot(data = xx, ggplot2::aes(x = !!rlang::sym('N'), y = p, group = !!rlang::sym('Bound'))) +
p <- ggplot2::ggplot(data = xx, ggplot2::aes(x = .data$N, y = p, group = .data$Bound)) +
ggplot2::geom_point() +
ggplot2::ylab("Rate at bound")
} else if (plottype == 2) {
Expand Down Expand Up @@ -386,13 +386,13 @@ plot.gsBinomialExact <- function(x, plottype = 1, ...) {
)
# combine and plot
outcome <- rbind(Power, futility, indeterminate)
p <- ggplot2::ggplot(data = outcome, ggplot2::aes(x = !!rlang::sym('rr'), y = !!rlang::sym('Percent'), lty = !!rlang::sym('Outcome'))) +
p <- ggplot2::ggplot(data = outcome, ggplot2::aes(x = .data$rr, y = .data$Percent, lty = .data$Outcome)) +
ggplot2::geom_line() +
ggplot2::xlab("Underlying response rate")
} else {
xx <- data.frame(N = x$n.I, x = x$upper$bound, Bound = "Upper")
xx <- rbind(xx, data.frame(N = x$n.I, x = x$lower$bound, Bound = "Lower"))
p <- ggplot2::ggplot(data = xx, ggplot2::aes(x = !!rlang::sym('N'), y = x, group = !!rlang::sym('Bound'))) +
p <- ggplot2::ggplot(data = xx, ggplot2::aes(x = .data$N, y = x, group = .data$Bound)) +
ggplot2::geom_point() +
ggplot2::ylab("Number of responses")
}
Expand Down
28 changes: 14 additions & 14 deletions R/gsqplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ gsCPz <- function(z, i, x, theta = NULL, ylab = NULL, ...) {
# qplotit roxy [sinew] ----
#' @importFrom graphics lines text
#' @importFrom ggplot2 ggplot aes geom_text geom_line scale_x_continuous scale_y_continuous scale_colour_manual scale_linetype_manual ggtitle xlab ylab
#' @importFrom rlang !! sym
#' @importFrom rlang .data
# qplotit function [sinew] ----
qplotit <- function(x, xlim = NULL, ylim = NULL, main = NULL, geom = c("line", "text"),
dgt = c(2, 2), lty = c(2, 1), col = c(1, 1),
Expand Down Expand Up @@ -398,8 +398,8 @@ qplotit <- function(x, xlim = NULL, ylim = NULL, main = NULL, geom = c("line", "
lbls <- c("Lower", "Upper")
if (x$test.type > 1) {
p <- ggplot2::ggplot(data = y, ggplot2::aes(
x = as.numeric(!!rlang::sym('N')), y = as.numeric(!!rlang::sym('Z')), group = factor(!!rlang::sym('Bound')),
col = factor(!!rlang::sym('Bound')), label = Ztxt, lty = factor(!!rlang::sym('Bound'))
x = as.numeric(.data$N), y = as.numeric(.data$Z), group = factor(.data$Bound),
col = factor(.data$Bound), label = Ztxt, lty = factor(.data$Bound)
)) +
ggplot2::geom_text(show.legend = F, size = cex * 5) +
ggplot2::geom_line() +
Expand All @@ -412,10 +412,10 @@ qplotit <- function(x, xlim = NULL, ylim = NULL, main = NULL, geom = c("line", "

} else {
p <- ggplot2::ggplot(ggplot2::aes(
x = as.numeric(!!rlang::sym('N')),
y = as.numeric(!!rlang::sym('Z')),
x = as.numeric(.data$N),
y = as.numeric(.data$Z),
label = Ztxt,
group = factor(!!rlang::sym('Bound'))),
group = factor(.data$Bound)),
data = y
) +
ggplot2::geom_line(colour = getColor(col[1]), lty = lty[1], lwd = lwd[1]) +
Expand All @@ -441,14 +441,14 @@ qplotit <- function(x, xlim = NULL, ylim = NULL, main = NULL, geom = c("line", "
graphics::text(x = y2$N, y = y2$Z, paste(rep("r=", x$k), y2$Ztxt, sep = ""), cex = cex)
} else {
y2$Ztxt <- paste(rep("r=", x$k), y2$Ztxt, sep = "")
p <- p + geom_text(data = y2, aes(group = factor(!!rlang::sym('Bound')), label = Ztxt), size = cex * 5, show.legend = F, colour = getColor(1))
p <- p + geom_text(data = y2, aes(group = factor(.data$Bound), label = Ztxt), size = cex * 5, show.legend = F, colour = getColor(1))
}
} else {
if (base) {
graphics::text(x = y2$N, y = y2$Z, paste(rep("N=", x$k), y2$Ztxt, sep = ""), cex = cex)
} else {
y2$Ztxt <- paste(rep("N=", x$k), y2$Ztxt, sep = "")
p <- p + ggplot2::geom_text(data = y2, ggplot2::aes(group = factor(!!rlang::sym('Bound')), label = Ztxt), size = cex * 5, show.legend = F, colour = getColor(1))
p <- p + ggplot2::geom_text(data = y2, ggplot2::aes(group = factor(.data$Bound), label = Ztxt), size = cex * 5, show.legend = F, colour = getColor(1))
}
}
}
Expand Down Expand Up @@ -741,7 +741,7 @@ plotsf <- function(x,
# plotASN roxy [sinew] ----
#' @importFrom graphics plot
#' @importFrom ggplot2 qplot
#' @importFrom rlang !! sym
#' @importFrom rlang .data
# plotASN function [sinew] ----
plotASN <- function(x, xlab = NULL, ylab = NULL, main = NULL, theta = NULL, xval = NULL, type = "l",
base = FALSE, ...) {
Expand Down Expand Up @@ -810,7 +810,7 @@ plotASN <- function(x, xlab = NULL, ylab = NULL, main = NULL, theta = NULL, xval
#' @importFrom stats reshape
#' @importFrom dplyr group_by reframe
#' @importFrom ggplot2 ggplot aes geom_line ylab guides guide_legend xlab scale_linetype_manual scale_color_manual scale_y_continuous ggtitle scale_x_continuous scale_colour_manual geom_text
#' @importFrom rlang !! sym
#' @importFrom rlang .data
#' @importFrom graphics plot axis lines strwidth text
#' @param offset Integer to offset the numeric labels of the "Analysis" legend
#' (default: 0). Only relevant for \code{outtype = 1}. By default will change
Expand Down Expand Up @@ -887,10 +887,10 @@ plotgsPower <- function(x, main = "Boundary crossing probabilities by effect siz

p <- ggplot2::ggplot(y2,
ggplot2::aes(
x = !!rlang::sym('delta'),
y = !!rlang::sym('Probability'),
col = !!rlang::sym('Bound'),
lty = !!rlang::sym('Analysis'))
x = .data$delta,
y = .data$Probability,
col = .data$Bound,
lty = .data$Analysis)
) +
ggplot2::geom_line(size = lwd) +
ggplot2::ylab(ylab) +
Expand Down

0 comments on commit 617338a

Please sign in to comment.