Advanced Summary Tables in R

Publication-Quality Visuals with gtExtras

Author

Abdullah Al Shamim

Published

February 13, 2026

What will we learn?

  • Automated Summaries: Generating instant visual overviews of any dataset.
  • Inline Graphics: Inserting distribution plots (sparklines) and bar charts directly into table cells.
  • Dynamic Styling: Using heatmaps and row highlighting to draw attention to key data.
  • Professional Theming: Applying styles from famous publications like The Guardian, ESPN, and the NY Times.

1. Environment Setup and Instant Summaries

The gtExtras package extends the gt (grammar of tables) package to provide high-level functions for data visualization within tables.

Code
# Load required libraries
library(svglite)
library(gtExtras)
library(tidyverse)
library(RColorBrewer)
library(gt)

# Create an instant visual summary of the Iris dataset
iris %>%
  gt_plt_summary(title = "Iris Dataset Summary")
Iris Dataset Summary
150 rows x 5 cols
Column Plot Overview Missing Mean Median SD
Sepal.Length 4.3 auto7.9 auto 0.0% 5.8 5.8 0.8
Sepal.Width 2.0 auto4.4 auto 0.0% 3.1 3.0 0.4
Petal.Length 1.0 auto6.9 auto 0.0% 3.8 4.3 1.8
Petal.Width 100 mauto2 auto 0.0% 1.2 1.3 0.8
Species setosa, versicolor and virginica
3 categories 0.0%

2. Inserting Graphics into Tables

Instead of looking at raw numbers, we can embed the distribution of data directly into the table using list-columns. This creates “sparklines” that provide visual context for numerical summaries.

Code
# Prepare data with a list-column for distribution
mtcars_summary <- mtcars %>% 
  group_by(cyl) %>% 
  summarize(Median = round(median(mpg), 1),
            Mean = round(mean(mpg), 1),
            Distribution = list(mpg))

# Visualize with sparklines (gt_plt_dist) and a professional theme
mtcars_summary %>% 
  gt() %>% 
  gt_plt_dist(Distribution) %>% 
  gt_theme_guardian() %>% 
  tab_header(title = "Miles Per Gallon Statistics",
             subtitle = "Comparing performance by cylinder count")
Miles Per Gallon Statistics
Comparing performance by cylinder count
cyl Median Mean Distribution
4 26.0 26.7
6 19.7 19.7
8 15.2 15.1

3. Advanced Country Analysis (Gapminder)

We can create highly complex tables that combine text, numbers, heatmaps, and bar charts to communicate multifaceted stories.

Code
library(gapminder)

# Step 1: Data Preparation and Base Table
plot_data <- gapminder %>% 
  rename(Country = country) %>% 
  filter(continent == "Asia") %>% 
  group_by(Country) %>% 
  summarise(
    "GDP per capita" = round(mean(gdpPercap)),
    "Population size" = round(mean(pop)),
    "Life expectancy" = list(lifeExp)) %>% 
  arrange(desc(`GDP per capita`)) %>% 
  head(10) %>% 
  gt() %>% 
  gt_plt_dist("Life expectancy") %>% 
  tab_header(title = "The GDP and Population Size of Asia") %>% 
  cols_align(align = "left")

# Display with ESPN theme
plot_data %>% gt_theme_espn()
The GDP and Population Size of Asia
Country GDP per capita Population size Life expectancy
Kuwait 65333 1206496
Saudi Arabia 20262 12478368
Bahrain 18078 373913
Japan 17751 111758808
Singapore 17425 2667817
Hong Kong, China 16229 4792259
Israel 14161 3845611
Oman 12139 1438205
Taiwan 10225 16874724
Korea, Rep. 8217 36499386

Adding Percentage Bars and Heatmap Colors

Using gt_plt_bar_pct, we can represent numerical values as horizontal bar charts within the cells, making comparisons much more intuitive.

Code
# Step 2: Adding visual intensity with bars and color scales
enhanced_plot <- plot_data %>% 
  gt_theme_espn() %>% 
  gt_color_rows(column = "Population size", 
                palette = "Pastel1") %>% 
  gt_plt_bar_pct("GDP per capita",
                 fill = "#d580ff",
                 height = 15,
                 width = 120)

enhanced_plot
The GDP and Population Size of Asia
Country GDP per capita Population size Life expectancy
Kuwait
1206496
Saudi Arabia
12478368
Bahrain
373913
Japan
111758808
Singapore
2667817
Hong Kong, China
4792259
Israel
3845611
Oman
1438205
Taiwan
16874724
Korea, Rep.
36499386

4. Highlighting and Professional Themes

To make specific findings stand out, we can highlight rows based on logical conditions—perfect for focusing on specific countries or outliers.

Row Highlighting

Code
# Highlighting specific countries (e.g., Bangladesh and China)
asian_table <- enhanced_plot %>% 
  gt_highlight_rows(
    rows = Country %in% c("Bangladesh", "China"),
    fill = "#f2e6ff")

asian_table
The GDP and Population Size of Asia
Country GDP per capita Population size Life expectancy
Kuwait
1206496
Saudi Arabia
12478368
Bahrain
373913
Japan
111758808
Singapore
2667817
Hong Kong, China
4792259
Israel
3845611
Oman
1438205
Taiwan
16874724
Korea, Rep.
36499386

5. Exploring Professional Themes

gtExtras provides built-in functions to mimic the typography, padding, and color schemes of world-class data journalism outlets. Use the tabs below to compare the styles.

The Guardian theme features a clean, modern look with specific header styling and increased row padding.

Code
asian_table %>% gt_theme_guardian()
The GDP and Population Size of Asia
Country GDP per capita Population size Life expectancy
Kuwait
1206496
Saudi Arabia
12478368
Bahrain
373913
Japan
111758808
Singapore
2667817
Hong Kong, China
4792259
Israel
3845611
Oman
1438205
Taiwan
16874724
Korea, Rep.
36499386

Inspired by FiveThirtyEight, this theme is optimized for data density, providing a crisp and informative look.

Code
asian_table %>% gt_theme_538()
The GDP and Population Size of Asia
Country GDP per capita Population size Life expectancy
Kuwait
1206496
Saudi Arabia
12478368
Bahrain
373913
Japan
111758808
Singapore
2667817
Hong Kong, China
4792259
Israel
3845611
Oman
1438205
Taiwan
16874724
Korea, Rep.
36499386

A classic, prestigious aesthetic characterized by minimal borders and high-end typography.

Code
asian_table %>% gt_theme_nytimes()
The GDP and Population Size of Asia
Country GDP per capita Population size Life expectancy
Kuwait
1206496
Saudi Arabia
12478368
Bahrain
373913
Japan
111758808
Singapore
2667817
Hong Kong, China
4792259
Israel
3845611
Oman
1438205
Taiwan
16874724
Korea, Rep.
36499386

A high-contrast dark mode theme ideal for dashboards or digital presentations.

Code
asian_table %>% gt_theme_dark()
The GDP and Population Size of Asia
Country GDP per capita Population size Life expectancy
Kuwait
1206496
Saudi Arabia
12478368
Bahrain
373913
Japan
111758808
Singapore
2667817
Hong Kong, China
4792259
Israel
3845611
Oman
1438205
Taiwan
16874724
Korea, Rep.
36499386

The classic spreadsheet look for users who prefer a familiar, structured grid layout.

Code
asian_table %>% gt_theme_excel()
The GDP and Population Size of Asia
Country GDP per capita Population size Life expectancy
Kuwait
1206496
Saudi Arabia
12478368
Bahrain
373913
Japan
111758808
Singapore
2667817
Hong Kong, China
4792259
Israel
3845611
Oman
1438205
Taiwan
16874724
Korea, Rep.
36499386

Systematic Checklist (Cheat Sheet):

  • Instant Summary: gt_plt_summary()
  • Sparklines/Distributions: gt_plt_dist()
  • Inline Percent Bars: gt_plt_bar_pct()
  • Conditional Coloring: gt_color_rows()
  • Row Highlighting: gt_highlight_rows()
  • Theming: gt_theme_...()

Excellent work! You have mastered the art of creating highly informative, publication-quality tables in R.