Skip to content

Commit

Permalink
Add byrow and layout_matrix parameters to arrange_ggsurvplot(). Fixes #…
Browse files Browse the repository at this point in the history
…300

Add byrow and layout_matrix parameters to arrange_ggsurvplot(), allowing
for more flexibility when laying out multi-plot pages.
  • Loading branch information
cbrueffer committed Oct 30, 2018
1 parent 1046ef7 commit 7d0b808
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions R/arrange_ggsurvplots.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#'@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 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 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.
Expand Down Expand Up @@ -47,7 +51,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, ...)
{

Expand All @@ -59,7 +65,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)

Expand Down

0 comments on commit 7d0b808

Please sign in to comment.