From f6c9a32fa5ac64a2b5b1e081198912484555ef56 Mon Sep 17 00:00:00 2001 From: Christian Brueffer Date: Tue, 30 Oct 2018 12:40:57 +0100 Subject: [PATCH 1/2] Add byrow and layout_matrix parameters to arrange_ggsurvplot(). Fixes #300 Add byrow and layout_matrix parameters to arrange_ggsurvplot(), allowing for more flexibility when laying out multi-plot pages. --- R/arrange_ggsurvplots.R | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/R/arrange_ggsurvplots.R b/R/arrange_ggsurvplots.R index a19d0c4..f9edd9f 100644 --- a/R/arrange_ggsurvplots.R +++ b/R/arrange_ggsurvplots.R @@ -5,14 +5,19 @@ #'@param x a list of ggsurvplots. #'@param print logical value. If TRUE, the arranged plots are displayed. #'@param title character vector specifying page title. Default is NA. -#'@param ncol,nrow the number of columns and rows, respectively. -#'@param risk.table.height the height of the risk table on the grid. Increase -#' the value when you have many strata. Default is 0.25. Ignored when -#' risk.table = FALSE. +#'@param ncol the number of columns. +#'@param nrow the number of rows. +#'@param byrow logical value. Whether to fill the plot matrix by rows, or by columns. +#' Default is FALSE (by columns). +#'@param layout_matrix optional layout matrix. If not specified, automatically +#' created from ncol, nrow, and byrow parameters. #'@param surv.plot.height the height of the survival plot on the grid. Default #' is 0.75. Ignored when risk.table = FALSE. \code{1-risk.table.height - #' ncensor.plot.height} when \code{risk.table = TRUE} and \code{ncensor.plot = #' TRUE} +#'@param risk.table.height the height of the risk table on the grid. Increase +#' the value when you have many strata. Default is 0.25. Ignored when +#' risk.table = FALSE. #'@param ncensor.plot.height The height of the censor plot. Used when #' \code{ncensor.plot = TRUE}. #'@param ... not used @@ -47,7 +52,9 @@ #' #'@rdname arrange_ggsurvplots #'@export -arrange_ggsurvplots <- function(x, print = TRUE, title = NA, ncol = 2, nrow = 1, surv.plot.height = NULL, +arrange_ggsurvplots <- function(x, print = TRUE, title = NA, ncol = 2, nrow = 1, byrow=FALSE, + layout_matrix = matrix(seq_len(nrow*ncol), nrow=nrow, + ncol=ncol, byrow=byrow), surv.plot.height = NULL, risk.table.height = NULL, ncensor.plot.height = NULL, ...) { @@ -59,7 +66,8 @@ arrange_ggsurvplots <- function(x, print = TRUE, title = NA, ncol = 2, nrow = 1 # Arrange multiple ggsurvplots survs <- do.call(gridExtra::marrangeGrob, - list(grobs = survs, ncol = ncol, nrow = nrow, top = title)) + list(grobs = survs, ncol = ncol, nrow = nrow, byrow = byrow, + layout_matrix = layout_matrix, top = title)) if(print) print(survs) From b0b6a39a6e74ad3d786e8766ff542121d7a60052 Mon Sep 17 00:00:00 2001 From: Christian Brueffer Date: Sat, 20 Mar 2021 13:44:27 +0100 Subject: [PATCH 2/2] Update roxygen docs. --- man/arrange_ggsurvplots.Rd | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/man/arrange_ggsurvplots.Rd b/man/arrange_ggsurvplots.Rd index 7bb0fbf..59b9a6d 100644 --- a/man/arrange_ggsurvplots.Rd +++ b/man/arrange_ggsurvplots.Rd @@ -10,6 +10,8 @@ arrange_ggsurvplots( title = NA, ncol = 2, nrow = 1, + byrow = FALSE, + layout_matrix = matrix(seq_len(nrow * ncol), nrow = nrow, ncol = ncol, byrow = byrow), surv.plot.height = NULL, risk.table.height = NULL, ncensor.plot.height = NULL, @@ -23,7 +25,15 @@ arrange_ggsurvplots( \item{title}{character vector specifying page title. Default is NA.} -\item{ncol, nrow}{the number of columns and rows, respectively.} +\item{ncol}{the number of columns.} + +\item{nrow}{the number of rows.} + +\item{byrow}{logical value. Whether to fill the plot matrix by rows, or by columns. +Default is FALSE (by columns).} + +\item{layout_matrix}{optional layout matrix. If not specified, automatically +created from ncol, nrow, and byrow parameters.} \item{surv.plot.height}{the height of the survival plot on the grid. Default is 0.75. Ignored when risk.table = FALSE. \code{1-risk.table.height -