Overview
In the pharmaceutical industry, and many other fields that rely heavily on data reporting, there is often a need to create figures and tables with specific graphical arrangements. These could be titles, subtitles, captions, footnotes, and other text elements that provide important context to the data being shown.
However, creating the headers and footers etc. and correctly positioning them around the output can be challenging, often requiring fine-tuning. This can be time-consuming and can lead to inconsistencies in the way the figures and tables are presented across different projects.
gridify builds on the base R grid package and makes it easy to add
flexible and customizable information around a figure or table using a
pre-defined or custom layout. The gridify package works with all of
the following input types, creating consistency when using various
different inputs:
grob, gtable, ggplot, flextable, gt, base R plots (by formula)
Whilst rtables are not directly supported, we can use rtables with gridify by first converting them to flextable (with rtables.officer).
As gridify is based on the graphical tool grid, any figure or table
inputs are converted to a grob object in gridify and the result of using
gridify is always a graphical image by design. By unifying
tables and figures into scalable vector graphics, gridify locks the
layout so it cannot break across environments — no shifting columns, no
reflowing text. The output is stable while the text stays clear, searchable,
and copy-able at any zoom level.
Installation
You can install the newest release version from CRAN:
install.packages("gridify")Or you can install the newest development version from Pharmaverse GitHub (example):
# install.packages("remotes") remotes::install_github("pharmaverse/gridify", build_manual = TRUE)
Example
The workflow of the package is as follows:
- Create your object (
ggplot,gtetc.) - Choose a layout (predefined or custom). Use
get_layouts()to see the predefined options - Use
gridify()to create agridifyobject - Print the
gridifyobject to see empty cells - Use
set_cell()to fill in the various text elements in the layout (headers, footers etc.)
The following example uses a table created by the gt package and the
gridify layout pharma_layout_base().