Table | the R Graph Gallery (2024)


Tables are an indispensable tool in data visualization. They offer a straightforward way to present complex data in an organized, easy-to-read format. R excels in table creation and manipulation, offering a range of packages like kableExtra, gt, reactable, and DT that provide extensive functionalities to suit various needs.
This section is rich in examples for each table-creation strategy, guiding you on which approach is best suited for different types of data and visualization goals.

How to make a table with R

Tables are powerful but complicated figures. As a result, there is a myriad of packages allowing to build them with R. It is easy to get lost!

I've tried to summarize the main packages in the following diagram:

Table | the R Graph Gallery (1)

The following document is organized following those 4 big families. For each package, I tried to explain when to use it and provided a few example with code to get started quickly.

1️⃣ GT, gtsummary and gtExtras

GT: Customizable, user-friendly R table

The GT package, stands for "Grammar of Tables". It was created by the RStudio team and first released in 2018. It offers an intuitive, tidyverse-inspired syntax, making table creation accessible, including for beginners.

GT's user-friendly design for handling complex formatting has quickly gained popularity in the R community. Its ease of use and readability make it a go-to choice for many R users seeking to create clear and aesthetically pleasing tables.

Introduction to gt A set of simple examples showing how to use the GT library.
Sub-headers How to create sub-headers with the gt library
Custom title A set of examples showing how to customize the titles of a table made with GT
Custom footer How to customize the footer and the references section of a gt table

gtsummary: summary statistics tables

gtSummary is a companion package to gt, specifically designed to enhance gt's capabilities in summarizing statistical findings. It bridges the gap between data analysis and table creation, allowing users to seamlessly generate summary tables directly from their analytical outputs.

By integrating with gt, gtSummary simplifies the process of transforming statistical results into well-organized and clear tables, ideal for reports or presentations.

Display regression results How to display results of your regression models in a beautiful table
Summary table Create summary table with both descriptive and inferential statistics, and even add your own custom functions!

gtExtras: more styling for gt

gtExtras augments and expands the functionalities of the gt package. It allows to create even more sophisticated and visually appealing tables.

It comes with a set of themes to make your table good-looking with just one more line of code. It provides functions to easily add plots in table cells. It also has helper functions to help with colors and icons.

Line chart Learn how to add a line chart in every cell of a table with gtExtras
Distribution With gtExtras, you can add a distribution plot in every cell, with multiple type of charts
Percentage bar How to add a percentage bar in a table cell with gtExtras
Summary table with charts Create summary table with descriptive statistics and charts with just one line of code!
Excel theme You can use a theme to make your table look like an Excel table
Dot matrix theme You can use a theme to make your table look like a dot matrix table
Dark theme You can use a theme to make your table look like a dark theme

2️⃣ kable and kableExtra for R Markdown documents

kable(): the table function of knitr

The knitr package is mainly made to render R Markdown documents. But it also has a kable() function that offers a simple and efficient way to create tables in R markdown documents.

kable() allows for quick conversion of data frames into tables.

kableExtra(): extending kable()

On the other hand, kableExtra serves as an extension to kable, significantly enhancing its capabilities. With kableExtra, users gain access to a wide range of styling and formatting options, such as adding stripes to rows, formatting text and cells, and even creating complex table layouts.

Customize colors in kableExtra tables Change background color, cell color or use a gradient of colors
Add links and images How to add links and images in a kableExtra table

3️⃣ Interactive tables with DT, reactable or formattable.

DT: easy filtering & sorting

DT stands for "DataTables", the Javascript library it interacts with. DT stands out for its ability to handle large datasets efficiently and its rich array of features like searching, sorting, and pagination.

I love adding a DT table at the beginning of my data analysis Quarto report. It provides access to your raw data easily!

Please check my full introduction to DT for more! Oh and this is how a DT table looks like:

See code

And a couple of additional examples to learn how to customize DT tables:

HTML content in table cells Add images, links, or any HTML content in a DT table
Filter, edit and add caption How to add a data-dependent filter, edit cell values and add caption to a DT table


reactable: unlimited cell customization

reactable allows to create interactive tables with extensive cell formatting capabilities.

It simplifies the process of embedding images within cells, it allows to create heat map-like tables through its advanced cell coloring features. Additionally, it offers unique functionalities for integrating bars or bubbles, further enhancing the visual appeal and informative value of the tables.

Reactable is also exceptionally effective for designing tables with expandable rows, making it an ideal choice for aggregating and presenting complex data sets in a user-friendly manner.

Column formatting How to format columns with date, currency or any numeric value in a reactable table
Clickable, interactive, and custom table How to create a fully customized table charts and clickable elements

Reactable can create some pretty amazing tables. Check this work by szymanskir for the R Studio table contest! Note: you can scroll, images are links, and the line chart is interactive.

See code

formattable

formattable is another great alternative when it comes to build interactive tables with R. Check its github repository for examples.

4️⃣ Other useful libraries.

flextable: best option for non-html output

flextable is another solid option to create very polish static tables. It supports a wide range of formatting options, including merging cells, rotating text, and conditional formatting.

It stands out due to its compatibility with various R Markdown formats, including Word, PowerPoint, and HTML.

rhandsontable: to manually edit cells

Rhandsontable provides an interactive table interface, allowing for direct editing of tables within a Shiny app or R Markdown document. It differentiates itself with features like dropdown menus, checkboxes, and calendar aids for data entry, emphasizing interactivity and user input.

It is best suited for applications requiring interactive data editing and manipulation within a web interface, such as Shiny applications.

modelsummary: for statistical model results

modelsummary is specialized for summarizing statistical models in R, offering a straightforward way to create elegant and comprehensive tables of model results.

It supports over one hundred types of models out-of-the-box, and allows users to report the results of those models side-by-side in a table, or in coefficient plots.

huxtable: for LaTeX output

huxtable focuses on creating simple yet elegant tables in R, with a strong emphasis on cross-format compatibility for LaTeX, HTML, and Word.

It is particularly appreciated by people in need for LaTeX outputs.

Related chart types

Barplot

Spider / Radar

Wordcloud

Parallel

Lollipop

Circular Barplot

Table | the R Graph Gallery (2024)
Top Articles
Latest Posts
Article information

Author: Dean Jakubowski Ret

Last Updated:

Views: 6056

Rating: 5 / 5 (70 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Dean Jakubowski Ret

Birthday: 1996-05-10

Address: Apt. 425 4346 Santiago Islands, Shariside, AK 38830-1874

Phone: +96313309894162

Job: Legacy Sales Designer

Hobby: Baseball, Wood carving, Candle making, Jigsaw puzzles, Lacemaking, Parkour, Drawing

Introduction: My name is Dean Jakubowski Ret, I am a enthusiastic, friendly, homely, handsome, zealous, brainy, elegant person who loves writing and wants to share my knowledge and understanding with you.