简体   繁体   中英

R - combine two gt objects in a single page output

In our production environment, we use gtsummary package to summarize large data, then convert to gt object to add title and subtitle. The visual quality of the resulting table is unparalleled.

However, in many instances we need this summary table accompanied by a companion data table that carries detail of a handful of outliers or similar specifics that clarify the overall. In a sense, this companion data is a table-based footnote, or clarifying support information.

Because we emit large numbers of these summaries, I am looking for a way to keep them together in the same emitted single-page pdf.

I've tried to solve this with the following:

  1. tbl_merge, tbl_stack in gtsummary: gtsummary tables, not gt objects, requires shared rows or columns.
  2. gridExtra: gt objects cannot be converted to grobs
  3. pdf() or print to device: gtsave or print(gt) does not output to device.

Does anyone know if there is there a way to embed one table as a png object in the footnote of the other? Or is there another alternative?

Found a really clean solution to this problem using the gt package. We needed to avoid converting tables into images, which strips the content of much functionality including machine search.

The solution: Tranform the supplemental table into html using as_raw_html(), then insert into the primary table as source_note using tab_source_note(source_note = html(suppTable).

This retains all formatting, including titles and footnotes for each of the tables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM