R/ggforce-facet-paginate.R

Defines functions n_pages

Documented in n_pages

#' Determine the number of pages in a paginated facet plot
#'
#' This is a simple helper that returns the number of pages it takes to plot all
#' panels when using \code{\link{facet_wrap_paginate}} . It partially builds the plot so depending
#' on the complexity of your plot it might take some time to calculate...
#'
#' @param plot A ggplot object using either facet_wrap_paginate or
#' facet_grid_paginate
#'
#' @return If the plot uses  using either facet_wrap_paginate or
#' facet_grid_paginate it returns the total number of pages. Otherwise it
#' returns NULL
#' @import ggplot2
#'
n_pages <- function(plot) {
  page <- ggplot_build(plot)$layout$panel_layout$page
  if (!is.null(page)) {
    max(page)
  } else {
    NULL
  }
}

Try the ggPMX package in your browser

Any scripts or data that you put into this service are public.

ggPMX documentation built on July 9, 2023, 7:45 p.m.