How to Make Beautiful Tables in R (2024)

Updated March 12, 2022 with info on the reactablefmtr and gtextras packages.

Want to learn to make beautiful tables?

Sign up for the course Making Beautiful Tables with R today!

It doesn't matter how good your data analysis is if you don't effectively communicate your results. In most reports, communication of results happens through a combination of data visualization and tables. Along with narrative text, these make up the bulk of content used to communicate results.

Clear writing is a topic for another venue. Data visualization in R is a huge topic (and one covered expertly in Kieran Healy's Data Visualization: A Practical Introduction and Claus Wilke's Fundamentals of Data Visualization). But what about tables? Fortunately for R users, there are many ways to create beautiful tables that effectively communicate your results.

Customizing Default Table Output in RMarkdown

If you are using RMarkdown (and, if you're not, you should really consider it), any data frame that you call in a code chunk is displayed using the data frame printing method set in your YAML. As Yihui Xie puts it, "printing objects in R code chunks basically emulates the R console." This default output leaves much to be desired. "Table" output with fixed-width fonts like this never inspired anyone to take action.

How to Make Beautiful Tables in R (1)

It is quite easy to improve this output. You can change the default data frame print method in the YAML to one of the following options.

How to Make Beautiful Tables in R (2)

Of these, the one most likely to improve your table output is paged, which creates paged tables that work well when you have particularly long tables and want to give users the ability to look at pieces of the output:

How to Make Beautiful Tables in R (3)

My Favorite R Packages to Make Tables

There are also many packages that provide functions to produce nicely formatted tables. Here are some of the packages I have used that produce tables that look good and effectively communicate results.

gt

gt is a new(ish) package. It “is designed to be both straightforward yet powerful … [with] an emphasis is on simple functions for the everyday display table needs.” The package has functions designed to do things like:

How to Make Beautiful Tables in R (4)

The gt package provides a general philosophy of tables (similar to the grammar of graphics theory that underlies the ggplot2 package) that enables it to be easy to use (with some practice) and extremely flexible.

Learn more about gt

gtextras

There’s also a package called gtextras that provides add-ons for the gt package. This package, by Thomas Mock, provides some nice themes like this modeled on New York Times tables.

How to Make Beautiful Tables in R (5)

The package also lets you add visualizations into tables, including sparklines and bar plots.

How to Make Beautiful Tables in R (6)

Learn more about gtextras.

kable + kableExtra

The kableExtra package builds on the kable output from the knitr package. As author Hao Zhu puts it:

The goal ofkableExtrais to help you build common complex tables and manipulate table styles. It imports the pipe%>%symbol frommagrittrand verbalize all the functions, so basically you can add “layers” to a kable output in a way that is similar withggplot2andplotly.

Sharla Gelfand used the kableExtra package in a report she did for the College of Nurses of Ontario and loved it.

How to Make Beautiful Tables in R (7)

Learn more about kableExtra

formattable

Kun Ren's formattable package" is designed for applying formatting on vectors and data frames to make data presentation easier, richer, more flexible and hopefully convey more information."

One of the most unique features is the ability to add colors, background shading, bars, and other features that move tables beyond hulking blocks of text.

How to Make Beautiful Tables in R (8)

If you're looking for an example of the formattable package in use, Laura Ellis has a really nice walkthrough.

Learn more about formattable

DT

The main appeal of the DT package is its ability to add filtering, pagination, and sorting to HTML tables. Users can slice, scroll through, and arrange tables in ways that help them to make sense of your results.

How to Make Beautiful Tables in R (9)

Learn more about DT

reactable

I had not heard of this package until Mara Averick tweeted about it recently. Though I haven't used it, the docs look incredible. Like the DT package, it offers the ability to sort and filter data. It's also much more visually appealing than the DT package. One of the examples (below) looks exactly like the gorgeous tables made by FiveThirtyEight.

How to Make Beautiful Tables in R (10)

Learn more about reactable

reactablefmtr

The reactable package can be a bit more challenging to work with. To simplify the process of creating tables in reactable, Kyle Cuilla developed the reactablefmtr package. As Kyle puts it:

The {reactablefmtr} package simplifies and enhances the styling and formatting of tables built with the {reactable}Rpackage. The {reactablefmtr} package provides many conditional formatters that are highly customizable and easy to use.

Among other things, the reactablefmtr package makes it easier to conditionally add colors to tables, add interactive sparklines, use custom themes, embed images in tables, and save tables in PNG and HTML format.

How to Make Beautiful Tables in R (11)

Learn more about reactablefmtr

flextable

The above packages are designed to produce HTML tables. If you are knitting to Word, your best for tables is the flextable package (though the tables this package produces can also be embedded within HTML and PDF outputs). Designed by David Gohel, the flextable package provides a straightforward syntax to shape the content and format of your tables.

How to Make Beautiful Tables in R (12)

Learn more about flextable

Packages Recommended by Others

The above packages are ones that I've used and had good success with. When I put the call out on Twitter for other packages to make tables in R, I got some promising-looking responses!

huxtable

The huxtable package produces:

LaTeX and HTML tables, with a friendly, modern interface. Features include control over text styling, number format, background color, borders, padding and alignment. Cells can span multiple rows and/or columns. Tables can be manipulated with standard R subsetting or dplyr functions.

How to Make Beautiful Tables in R (13)

Learn more about huxtable

rhandsontable

Like the DT package, the rhandsontable package gives users the ability to manipulate data in tables. It comes with "powerful features like data validation, sorting, grouping, data binding, formula support or column ordering." Working with tables feels like viewing data in Excel, which can be helpful for users used to working with Microsoft's ubiquitous spreadsheet program. Users can even make changes to data in tables made with this package.

How to Make Beautiful Tables in R (14)

Learn more about rhandsontable

pixiedust

The fantastically-named pixedust package is designed to produce a specific type of table: model output that has been tidied using the broom package. Using pixiedust is a three-step process:

  1. Run your model using a base R function (e.g. lm for a linear model)

  2. Use the tidy function from the broom package to convert the results into a tidy format

  3. Use the pixiedust package (the sprinkle_ set of functions in particular) to improve the output, removing “stats-speak” and putting it into a “format that is suitable for publication or submission to a client.”

The sprinkle_ functions enable you to do things like removing excess decimal places, convert p-values to not use scientific notation, and more.

How to Make Beautiful Tables in R (15)

If you want to ensure that end users read and understand the results of your complex statistical analyses, this looks like a great package!

Learn more about pixiedust

There are surely more table packages that I've missed (in wrapping up this post, I came across this list from the RStudio RMarkdown tutorials), but this should give you a good place to start in making your tables more beautiful and more effective.

How to Make Beautiful Tables in R (2024)

References

Top Articles
Tire Depot Lynchburg Va
World Of Warcraft Best Rp Server
Funny Roblox Id Codes 2023
Golden Abyss - Chapter 5 - Lunar_Angel
Www.paystubportal.com/7-11 Login
Joi Databas
DPhil Research - List of thesis titles
Shs Games 1V1 Lol
Evil Dead Rise Showtimes Near Massena Movieplex
Steamy Afternoon With Handsome Fernando
Which aspects are important in sales |#1 Prospection
Detroit Lions 50 50
18443168434
Newgate Honda
Zürich Stadion Letzigrund detailed interactive seating plan with seat & row numbers | Sitzplan Saalplan with Sitzplatz & Reihen Nummerierung
Grace Caroline Deepfake
978-0137606801
Nwi Arrests Lake County
Justified Official Series Trailer
London Ups Store
Committees Of Correspondence | Encyclopedia.com
Pizza Hut In Dinuba
Jinx Chapter 24: Release Date, Spoilers & Where To Read - OtakuKart
How Much You Should Be Tipping For Beauty Services - American Beauty Institute
Free Online Games on CrazyGames | Play Now!
Sizewise Stat Login
VERHUURD: Barentszstraat 12 in 'S-Gravenhage 2518 XG: Woonhuis.
Jet Ski Rental Conneaut Lake Pa
Unforeseen Drama: The Tower of Terror’s Mysterious Closure at Walt Disney World
Kcwi Tv Schedule
What Time Does Walmart Auto Center Open
Nesb Routing Number
Olivia Maeday
Random Bibleizer
10 Best Places to Go and Things to Know for a Trip to the Hickory M...
Black Lion Backpack And Glider Voucher
Gopher Carts Pensacola Beach
Duke University Transcript Request
Lincoln Financial Field, section 110, row 4, home of Philadelphia Eagles, Temple Owls, page 1
Jambus - Definition, Beispiele, Merkmale, Wirkung
Ark Unlock All Skins Command
Craigslist Red Wing Mn
D3 Boards
Jail View Sumter
Nancy Pazelt Obituary
Birmingham City Schools Clever Login
Thotsbook Com
Funkin' on the Heights
Vci Classified Paducah
Www Pig11 Net
Ty Glass Sentenced
Latest Posts
Article information

Author: Terence Hammes MD

Last Updated:

Views: 5482

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Terence Hammes MD

Birthday: 1992-04-11

Address: Suite 408 9446 Mercy Mews, West Roxie, CT 04904

Phone: +50312511349175

Job: Product Consulting Liaison

Hobby: Jogging, Motor sports, Nordic skating, Jigsaw puzzles, Bird watching, Nordic skating, Sculpting

Introduction: My name is Terence Hammes MD, I am a inexpensive, energetic, jolly, faithful, cheerful, proud, rich person who loves writing and wants to share my knowledge and understanding with you.