From 2671e9fba0b218fe0f51802e006f5724dd76f70e Mon Sep 17 00:00:00 2001 From: Zygmunt Zawadzki Date: Mon, 16 Jan 2017 10:31:39 +0100 Subject: [PATCH 1/2] https://github.com/kassambara/survminer/issues/110 --- R/ggsurvplot.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/ggsurvplot.R b/R/ggsurvplot.R index 8c0e002..97e0123 100644 --- a/R/ggsurvplot.R +++ b/R/ggsurvplot.R @@ -581,7 +581,7 @@ print.ggsurvplot <- function(x, surv.plot.height = NULL, risk.table.height = NUL for (i in 1:length(grobs)) { grobs[[i]]$widths[2:5] <- as.list(maxwidth) } - do.call(gridExtra::grid.arrange, c(grobs, nrow = nplot, heights = heights )) + do.call(gridExtra::grid.arrange, c(grobs, nrow = nplot, heights = heights, newpage = FALSE)) } } From 4ace7abb6937dc171322e92a44edd8cc080cff23 Mon Sep 17 00:00:00 2001 From: Zygmunt Zawadzki Date: Mon, 16 Jan 2017 20:50:15 +0100 Subject: [PATCH 2/2] Add newpage = TRUE to print interface. With newpage = FALSE ReporteR output can be created. --- R/ggcoxfunctional.R | 5 +++-- R/ggcoxzph.R | 5 +++-- R/ggsurvplot.R | 5 +++-- R/surv_cutpoint.R | 5 +++-- man/ggcoxfunctional.Rd | 4 +++- man/ggcoxzph.Rd | 4 +++- man/ggsurvplot.Rd | 5 ++++- man/surv_cutpoint.Rd | 4 +++- 8 files changed, 25 insertions(+), 12 deletions(-) diff --git a/R/ggcoxfunctional.R b/R/ggcoxfunctional.R index 7ebdf66..7042f54 100644 --- a/R/ggcoxfunctional.R +++ b/R/ggcoxfunctional.R @@ -94,10 +94,11 @@ ggcoxfunctional <- function (formula, data, iter = 0, f = 0.6, #' @param x an object of class ggcoxfunctional #' @param ... further arguments passed to print, but really it's unused +#' @param newpage open a new page. See \code{\link{grid.arrange}}. #' @method print ggcoxfunctional #' @rdname ggcoxfunctional #' @export -print.ggcoxfunctional <- function(x, ...){ +print.ggcoxfunctional <- function(x, ..., newpage = TRUE){ if(!inherits(x, "ggcoxfunctional")) stop("An object of class ggcoxfunctional is required.") plots <- x @@ -111,6 +112,6 @@ print.ggcoxfunctional <- function(x, ...){ grobs[[i]]$widths[2:5] <- as.list(maxwidth) } y.text <- attr(plots, "y.text") - do.call(gridExtra::grid.arrange, c(grobs, left = y.text)) + do.call(gridExtra::grid.arrange, c(grobs, left = y.text, newpage = newpage)) } diff --git a/R/ggcoxzph.R b/R/ggcoxzph.R index 1f89440..16ba259 100644 --- a/R/ggcoxzph.R +++ b/R/ggcoxzph.R @@ -153,10 +153,11 @@ ggcoxzph <- function (fit, resid = TRUE, se = TRUE, df = 4, nsmo = 40, var, #' @param x an object of class ggcoxzph #' @param ... further arguments passed to print, but really it's unused +#' @param newpage open a new page. See \code{\link{grid.arrange}}. #' @method print ggcoxzph #' @rdname ggcoxzph #' @export -print.ggcoxzph <- function(x, ...){ +print.ggcoxzph <- function(x, ..., newpage = TRUE){ if(!inherits(x, "ggcoxzph")) stop("An object of class ggcoxzph is required.") plots <- x @@ -173,6 +174,6 @@ print.ggcoxzph <- function(x, ...){ if(!is.null(pval)) main <- paste0("Global Schoenfeld Test p: ", signif(pval, 4), "\n") else main <- NULL - do.call(gridExtra::grid.arrange, c(grobs, top = main)) + do.call(gridExtra::grid.arrange, c(grobs, top = main, newpage = newpage)) } diff --git a/R/ggsurvplot.R b/R/ggsurvplot.R index 97e0123..d7eba6d 100644 --- a/R/ggsurvplot.R +++ b/R/ggsurvplot.R @@ -530,10 +530,11 @@ ggsurvplot <- function(fit, fun = NULL, } #' @param x an object of class ggsurvplot +#' @param newpage open a new page. See \code{\link{grid.arrange}}. #' @method print ggsurvplot #' @rdname ggsurvplot #' @export -print.ggsurvplot <- function(x, surv.plot.height = NULL, risk.table.height = NULL, ncensor.plot.height = NULL, ...){ +print.ggsurvplot <- function(x, surv.plot.height = NULL, risk.table.height = NULL, ncensor.plot.height = NULL, ..., newpage = TRUE){ if(!inherits(x, "ggsurvplot")) stop("An object of class ggsurvplot is required.") @@ -581,7 +582,7 @@ print.ggsurvplot <- function(x, surv.plot.height = NULL, risk.table.height = NUL for (i in 1:length(grobs)) { grobs[[i]]$widths[2:5] <- as.list(maxwidth) } - do.call(gridExtra::grid.arrange, c(grobs, nrow = nplot, heights = heights, newpage = FALSE)) + do.call(gridExtra::grid.arrange, c(grobs, nrow = nplot, heights = heights, newpage = newpage)) } } diff --git a/R/surv_cutpoint.R b/R/surv_cutpoint.R index eb9967f..478f0e9 100644 --- a/R/surv_cutpoint.R +++ b/R/surv_cutpoint.R @@ -241,10 +241,11 @@ plot.surv_cutpoint <- function(x, variables = NULL, ggtheme = theme_classic2(), p } +#' @param newpage open a new page. See \code{\link{grid.arrange}}. #' @method print plot_surv_cutpoint #' @rdname surv_cutpoint #' @export -print.plot_surv_cutpoint <- function(x, ...){ +print.plot_surv_cutpoint <- function(x, ..., newpage = TRUE){ if(!inherits(x, "plot_surv_cutpoint")) stop("x must be an object of class plot_surv_cutpoint.") x$distribution <- x$distribution + theme(legend.position = "none")+labs(x = NULL) @@ -264,7 +265,7 @@ print.plot_surv_cutpoint <- function(x, ...){ cutpoint <- attr(x, "cutpoint") main <- name <- attr(x, "name") # main <- paste0(name,"- cutpoint: ", attr(x, "cutpoint")) - do.call(gridExtra::grid.arrange, c(grobs, top = main)) + do.call(gridExtra::grid.arrange, c(grobs, top = main, newpage = newpage)) } diff --git a/man/ggcoxfunctional.Rd b/man/ggcoxfunctional.Rd index 62c4a2e..4036f9c 100644 --- a/man/ggcoxfunctional.Rd +++ b/man/ggcoxfunctional.Rd @@ -12,7 +12,7 @@ ggcoxfunctional(formula, data, iter = 0, f = 0.6, point.col = "red", ylim = NULL, ylab = "Martingale Residuals \\nof Null Cox Model", ggtheme = theme_classic2()) -\method{print}{ggcoxfunctional}(x, ...) +\method{print}{ggcoxfunctional}(x, ..., newpage = TRUE) } \arguments{ \item{formula}{a formula object, with the response on the left of a ~ operator, and the terms on the right. The response must be a survival object as returned by the \link{Surv} function.} @@ -42,6 +42,8 @@ Allowed values include ggplot2 official themes: see \code{\link[ggplot2]{theme}} \item{x}{an object of class ggcoxfunctional} \item{...}{further arguments passed to print, but really it's unused} + +\item{newpage}{open a new page. See \code{\link{grid.arrange}}.} } \value{ Returns an object of class \code{ggcoxfunctional} which is a list of ggplots. diff --git a/man/ggcoxzph.Rd b/man/ggcoxzph.Rd index 35f6243..2ac160f 100644 --- a/man/ggcoxzph.Rd +++ b/man/ggcoxzph.Rd @@ -11,7 +11,7 @@ ggcoxzph(fit, resid = TRUE, se = TRUE, df = 4, nsmo = 40, var, font.y = c(14, "plain", "black"), font.tickslab = c(12, "plain", "black"), ggtheme = theme_classic2()) -\method{print}{ggcoxzph}(x, ...) +\method{print}{ggcoxzph}(x, ..., newpage = TRUE) } \arguments{ \item{fit}{an object of class \link{cox.zph}.} @@ -45,6 +45,8 @@ Allowed values include ggplot2 official themes: see \code{\link[ggplot2]{theme}} \item{x}{an object of class ggcoxzph} \item{...}{further arguments passed to print, but really it's unused} + +\item{newpage}{open a new page. See \code{\link{grid.arrange}}.} } \value{ Returns an object of class \code{ggcoxzph} which is a list of ggplots. diff --git a/man/ggsurvplot.Rd b/man/ggsurvplot.Rd index 2e6e68f..c1b97bc 100644 --- a/man/ggsurvplot.Rd +++ b/man/ggsurvplot.Rd @@ -27,7 +27,8 @@ ggsurvplot(fit, fun = NULL, color = NULL, palette = "hue", linetype = 1, ggtheme = theme_classic2(), ...) \method{print}{ggsurvplot}(x, surv.plot.height = NULL, - risk.table.height = NULL, ncensor.plot.height = NULL, ...) + risk.table.height = NULL, ncensor.plot.height = NULL, ..., + newpage = TRUE) } \arguments{ \item{fit}{an object of class survfit.} @@ -149,6 +150,8 @@ line at median survival. Allowed values include one of c("none", "hv", "h", linetype, size, ...} \item{x}{an object of class ggsurvplot} + +\item{newpage}{open a new page. See \code{\link{grid.arrange}}.} } \value{ return an object of class ggsurvplot which is list containing two diff --git a/man/surv_cutpoint.Rd b/man/surv_cutpoint.Rd index a1e168b..aad2656 100644 --- a/man/surv_cutpoint.Rd +++ b/man/surv_cutpoint.Rd @@ -21,7 +21,7 @@ surv_categorize(x, variables = NULL, labels = c("low", "high")) \method{plot}{surv_cutpoint}(x, variables = NULL, ggtheme = theme_classic2(), bins = 30, ...) -\method{print}{plot_surv_cutpoint}(x, ...) +\method{print}{plot_surv_cutpoint}(x, ..., newpage = TRUE) } \arguments{ \item{data}{a data frame containing survival information (time, event) and @@ -49,6 +49,8 @@ shown only, when the number of variables > 5.} ?ggplot2::ggtheme.} \item{bins}{Number of bins for histogram. Defaults to 30.} + +\item{newpage}{open a new page. See \code{\link{grid.arrange}}.} } \value{ \itemize{