{gt} tables for scientific projects

Author

Eva Maleckova

Published

October 14, 2025

The Table Contest

The Table Contest by Posit is an annual event and this book is a tutorial contribution for the 2025 edition.

1 Motivation

I am making this tutorial for some six years younger me. I was in the second year of graduate school, working on my first manuscripts and gaining first experiences with R - specifically, with analysis of mRNA-sequencing data and making first visualizations with the {ggplot2}. While it felt natural to create figures programmatically, I never considered this option for tables and unfortunately did not develop a lot in this regard by the time I was writing my thesis. Luckily, I discovered the {gt} package for my current job and can say:

Who wants reproducible, well-documented work and matching visual elements throughtout various outputs should pay attention to the {gt} package.

My aim is to show that with the {gt} package, it is possible to create a minimalist summary tables ready for a publication (Chapter 3), a small table accompanying a chart (Chapter 4) as well as visually advanced tables suitable - e.g., for a poster - (Chapter 5) and even interactive tables - e.g., for a laboratory/project website (Chapter 6). For scientific topics, we may have special requirements such as italicized taxonomic names, use of subscripts or Greek characters. Thanks to {gt}’s inbuilt formatting options and support of markdown and HTML notions, all of these are easy tasks.

Throught the chapters of this book, we will see that with only minimal customizations, we can create very nice tables. In chapters of this tutorial, we will see how much of an impact a little bit of HTMLand CSS can have to control the overall table design (Chapter 5) or to fine-tune positioning of elements (specifically a footnote in Chapter 7).

Ideally, our work on a bigger analysis or a project will be structured as an R project covering the entire pipeline from data preprocessing to exploratory analysis and to generation of outputs such as figures and tables. It is common to provide supplementary materials to a manuscript - for example, a table summarizing our data at a suitable level of detail. This is why Chapter 8 provides a little teaser on use of {openxlsx2} package.

2 Data

We will use the vegetation dataset available with the {folio} package. It is a collection of measurements of 12C and 13C isotopes in 32 plant familie of C3 and C4 species. The data was generated by T. E. Cerling & J. M. Harris (1999).

Isotopic discrimination

Depending on the type of photosynthesis, different plant species show different level of discrimination between 12C and 13C (both stable) isotopes. In an experimental procedure, the ratio* in a sample (here, a green leaf of selected plant species) is compared to ratio in a standard and the difference is reported as parts per thousand: thus the notion δ13C. Plants preferentially take up the “light” 12C isotope over the “heavier” 13C isotopic, resulting in negative ratio. Species which evolved C4 of photosynthesis, however, take up 13C more frequently which is detectable as a less negative δ13C value.

* \(δ \ ^{13}C = (\frac{ratio \ in \ sample}{ratio \ in \ standard} - 1) * 1000\)