Top 7 Packages for Making Beautiful Tables in R (2024)

Top 7 Packages for Making Beautiful Tables in R (3)

Developing meaningful visualizations is an essential yet challenging task in data science. Along with the correct choice of tools, a general understanding of the target audience and the goal of the analysis is also expected in any data analysis. In the same context, tables are a powerful and efficient way of organizing and summarizing any available dataset, especially containing categorical variables. Tables are often used in reports along with supporting data visualizations to communicate the results of data analysis effectively. With some relevant narrative text, tables can precisely share the analysis findings for decision-making in an organization. Although Data visualization in R is a vast topic in itself due to the availability of several robust and easy-to-use plotting libraries, the same can be said about tables in R. The CRAN website offers many open-source packages for R users. These packages can not just create tables but also transform the basic tables into beautiful tables that effectively communicate the analysis findings.

In this article, we will discuss seven interesting packages for building colorful tables in R.

Several R packages offer features to create nicely structured tables. Here are a few packages we’ll use to create beautiful tables.

  1. gt (License: MIT)

The gt package offers a different and easy-to-use set of functions that helps us build display tables from tabular data. The gt philosophy states that a comprehensive collection of table parts can be used to create a broad range of functional tables. These are the table body, the table footer, the spanner column labels, the column labels, and the table header. Below is an illustration of the gt package’s architecture:

Top 7 Packages for Making Beautiful Tables in R (4)

The output formats that gt currently supports are HTML, LaTeX, and RTF. You can find more about gt here. For installing the gt package from CRAN, use the following command:

install.packages(“gt”)

For installing the development version of gt from GitHub, use the following commands:

devtools::install_github(“rstudio/gt”)

Next, we will import the gt library package.

library(gt)

Let’s take the mtcars dataset from the pre-installed datasets of R. This dataset was extracted from the Motor Trend US Magazine (1974) and consists of information on the fuel consumption along with 10 attributes of automotive design and performance of 32 cars (1973 and 1974 models). We can print the first few rows of the ‘mtcars’ dataset using the following command:

head(mtcars)
Top 7 Packages for Making Beautiful Tables in R (5)

Next, we create a new dataframe df using the first few columns and rows from the dataset mtcars.

We will call the main function “gt” with our newly created dataframe “df.” The table will appear on your default browser or the Viewer panel if you use RStudio or another R GUI.

df %>%gt()
Top 7 Packages for Making Beautiful Tables in R (6)

The table we created is a simple table, as the formatting properties used are the default properties. The default appearance of the tables can be changed by using the tab_style() function, through which we can target specific cells and apply styles to them.

df %>%gt() %>%
tab_header(title = “mtcars dataset”) %>%
tab_style(
style = list(cell_fill(color = “#b2f7ef”),
cell_text(weight = “bold”)),
locations = cells_body(columns = mpg))%>%
tab_style(
style = list(cell_fill(color = “#ffefb5”),
cell_text(weight = “bold”)),
locations = cells_body(columns = hp))
Top 7 Packages for Making Beautiful Tables in R (7)

2. formattable (License: MIT + file LICENSE):

Formattable data frames are data frames that will be displayed in HTML tables using formatter functions. This package includes techniques to produce data structures with predefined formatting rules, such that the objects maintain the original data but are formatted. The package consists of several standard formattable objects, including percent, comma, currency, accounting, and scientific. You can find more about formattable here.

For installing the formattable package from CRAN, use the following command:

install.packages(“formattable”)

For installing the development version of formattable from GitHub, use the following commands:

devtools::install_github(“renkun-ken/formattable”)

Next, we will import the formattable library package.

library(formattable)

To demonstrate this library, we will use the built-in function color_bar() to compare the magnitude of values in given columns of data.

formattable(df, list(
hp = color_bar(“#e9c46a”),
cyl = color_bar(“#80ed99”),
wt = color_bar(“#48cae4”),
disp = color_bar(“#f28482”)))
Top 7 Packages for Making Beautiful Tables in R (8)

3. kableExtra (License: MIT + file LICENSE)

The kableExtra package is used to extend the basic functionality of knitr::kable tables(). Although knitr::kable() is simple by design, it has many features missing which are usually available in other packages, and kableExtra has filled the gap nicely for knitr::kable(). The best thing about kableExtra is that most of its table capabilities work for both HTML and PDF formats. You can find more about kableExtra here.

For installing the kableExtra package from CRAN, use the following command:

install.packages(“kableExtra”)

For installing the development version of kableExtra from GitHub, use the following commands:

remotes::install_github(“haozhu233/kableExtra”)

Next, we will import the kableExtra library package.

library(kableExtra)

We will call the kbl function with dataframe “df” to view the basic version of the table.

kable(df) %>% kable_styling(latex_options = “striped”)
Top 7 Packages for Making Beautiful Tables in R (9)

To style individual rows and columns, we can use the functions row_spec() and column_spec().

df %>% kbl() %>%
kable_paper() %>% column_spec(2, color = “white”,
background = spec_color(mtcars$drat[1:2],end = 0.7)) %>%
column_spec(5, color = “white”,
background = spec_color(mtcars$drat[1:6], end = 0.7),
popover = paste(“am:”, mtcars$am[1:6]))
Top 7 Packages for Making Beautiful Tables in R (10)

4. dt (License: GPL-3)

dt is an abbreviation of ‘DataTables.’ Data objects in R can be rendered as HTML tables using the JavaScript library ‘DataTables’ (typically via R Markdown or Shiny). You can find more about dt here.

For installing the dt package from CRAN, use the following command:

install.packages(‘DT’)

For installing the development version of dt from GitHub, use the following command:

remotes::install_github(‘rstudio/DT’)

Next, we will import the dt library package.

library(DT)

The DT package’s main feature is its ability to provide filtering, pagination, and sorting to HTML tables. By using this package, we can slice, scroll through, and arrange tables to understand the table contents better.

datatable(
data = mtcars,
caption = “Table”,
filter = “top”
)
Top 7 Packages for Making Beautiful Tables in R (11)

5. flextable (License: GPL-3)

flextable package helps you to create reporting table from a dataframe easily. You can merge cells, add headers, add footers, change formatting, and set how data in cells is displayed. Table content can also contain mixed types of text and image content. Tables can be embedded from R Markdown documents into HTML, PDF, Word, and PowerPoint documents and can be embedded using Package Officer for Microsoft Word or PowerPoint documents. Tables can also be exported as R plots or graphic files, e.g., png, pdf, and jpeg. You can find more about flextable here.

For installing the flextable package from CRAN, use the following command:

install.packages(“flextable”)

For installing the development version of flextable from GitHub, use the following command:

devtools::install_github(“davidgohel/flextable”)

Next, we will import the flextable library package.

library(flextable)

For this library, the main function is flextable. We will call the flextable function to view the basic version of the table as shown below:

flextable(df)
Top 7 Packages for Making Beautiful Tables in R (12)

We will use the set_flextable_defaults function to change the default appearance of the table.

set_flextable_defaults(
font.family = “Arial”, font.size = 10,
border.color = “#e5383b”,
padding = 6,
background.color = “#EFEFEF”)
flextable(head(df)) %>%
bold(part = “header”)
Top 7 Packages for Making Beautiful Tables in R (13)

6. reactable (License: MIT + file LICENSE)

reactable() creates a data table from tabular data with sorting and pagination by default. The data table is an HTML widget that can be used in R Markdown documents and Shiny applications or viewed from an R console. It is based on the React Table library and made with reactR. There are many features of reactable; some of them are given below:

  • It creates a data table with sorting, filtering, and pagination
  • It has built-in column formatting
  • It supports custom rendering via R or JavaScript
  • It works seamlessly within R Markdown documents and the Shiny app

For installing the reactable package from CRAN, use the following command:

install.packages(“reactable”)

For installing the development version of reactable from GitHub, use the following commands:

# install.packages(“devtools”)
devtools::install_github(“glin/reactable”)

Next, we will import the reactable library package.

library(reactable)

We will use the reactable() function to create a data table. The table will be sortable and paginated by default:

reactable(mtcars)
Top 7 Packages for Making Beautiful Tables in R (14)

To change the table’s default appearance, we will use the reactableTheme() function. The global reactable.theme option can also be used if you want to set the default theme for all tables.

library(reactable)
reactable(mtcars)
options(reactable.theme = reactableTheme(
color = “black”,
backgroundColor = “#bde0fe”,
borderColor = “#a3b18a”,
stripedColor = “#a3b18a”,
highlightColor = “#2b2d42”
))
Top 7 Packages for Making Beautiful Tables in R (15)

7. reactablefmtr (License: MIT + file LICENSE)

The reactablefmtr package improves the appearance and formatting of tables created using the reactable R library. The reactablefmtr package includes many conditional formatters that are highly customizable and easy to use.

For installing the reactablefmtr package from CRAN, use the following command:

install.packages(“reactablefmtr”)

For installing the development version of reactablefmtr from GitHub, use the following commands:

remotes::install_github(“kcuilla/reactablefmtr”)

The reactable package in R allows you to create interactive data tables. However, formatting tables inside reactable requires a large amount of code, which might be challenging for many R users and needs to be more scalable. The data_bars() function in the reactablefmtr library makes it much easier to create bar charts.

library(reactablefmtr)
reactable(data,defaultColDef = colDef(
cell = data_bars(data,text_position = “outside-base”)
))
Top 7 Packages for Making Beautiful Tables in R (16)

There are several ways to alter the appearance of data_bars(), including bar alignment, text label location, and the ability to add icons and images to the bars.

library(reactablefmtr)
reactable(data,defaultColDef = colDef(cell = data_bars(df, box_shadow = TRUE, round_edges = TRUE,
text_position = “outside-base”,
fill_color = c(“#e81cff”, “#40c9ff”),
background = “#e5e5e5”,fill_gradient = TRUE)
))
Top 7 Packages for Making Beautiful Tables in R (17)

Conclusion

In this article, we discussed seven powerful R packages to create beautiful tables for a given dataset. There are many more R libraries, and indeed some new ones will also be developed in the future. But this tutorial can be helpful to get started with these packages for anyone looking to create more beautiful and effective tables in R.

You can follow me on: GitHub, Kaggle, Twitter and LinkedIn.

Top 7 Packages for Making Beautiful Tables in R (2024)

FAQs

What is the best package for tables in R? ›

flextable (Gohel and Skintzos 2023) and huxtable (Hugh-Jones 2024): If you are looking for a table package that supports the widest range of output formats, flextable and huxtable are probably the two best choices.

What is the package for data table function in R? ›

table R package provides an enhanced version of data. frame that allows you to do blazing fast data manipulations. The data. table R package is being used in different fields such as finance and genomics and is especially useful for those of you that are working with large data sets (for example, 1GB to 100GB in RAM).

How do you make a beautiful data table? ›

Use colors and lines to help readers navigate your table. Highlight important cells by applying a subtle background color or group related values by creating thicker lines. Include the source of your data to make your table look more professional and allow readers to analyze the topic more deeply.

Is data table better than tidyverse? ›

table and tidyverse . In cases when we are handling very large dataset, data. table would be a good choice since it runs extremely fast. In cases when we are not requiring the speed so much, especially when collaborating with others, we can choose tidyverse since its code is more readable.

Which program is best for tables? ›

Despite its basic data visualization capabilities, Microsoft Excel Online is a powerful tool. It allows users to create, edit, and share spreadsheets, table charts, and other types of charts. The platform offers a wide range of templates and pre-built formulas to make this process as easy as possible.

How do you format a table to look nice? ›

Create a custom table style
  1. Select any cell in the table you want to use to create a custom style.
  2. On the Home tab, click Format as Table, or expand the Table Styles gallery from the Table Tools > Design tab (the Table tab on a Mac).
  3. Click New Table Style, which will launch the New Table Style dialog.

How do you make an awesome table? ›

Create your first Awesome Table app
  1. Tutorial: Create your first Awesome Table app.
  2. Step 1: Create and set up your data source.
  3. Step 2: Create and set up a Table app in Awesome Table.
  4. Step 3: Customize how data is displayed in your app.
  5. Step 4: Embed your app on your website.

How do you make a cute table? ›

Table Decorating Tips
  1. Curate your colour theme. Adopting a few key colours will help make your table look harmonious and balanced. ...
  2. Layer up your linens. A tablecloth doesn't have to just be practical, think of it as your blank canvas — the foundation of your tablescape. ...
  3. Create a centrepiece. ...
  4. Mix old with new.
May 15, 2021

Is a data table faster than dplyr? ›

dplyr shows great memory efficiency in summarizing, while data. table is generally the fastest approach.

Can you use dplyr with data tables? ›

dtplyr provides a data. table backend for dplyr. The goal of dtplyr is to allow you to write dplyr code that is automatically translated to the equivalent, but usually much faster, data. table code.

What are data packages in R? ›

R packages are extensions to the R statistical programming language. R packages contain code, data, and documentation in a standardised collection format that can be installed by users of R, typically via a centralised software repository such as CRAN (the Comprehensive R Archive Network).

How do you beautify a table? ›

Steps for a better table
  1. Clear out the default formatting. Depending on your template, your default table format could have all sorts of table borders, fill and font formatting. ...
  2. Format header row. ...
  3. Add row borders. ...
  4. Adjust the margins. ...
  5. Text alignment. ...
  6. Format the bottom row (if relevant)
Nov 10, 2023

What makes a table aesthetically pleasing? ›

Making figures and tables look good requires you to consider elements such as color, organization, readability, and visual clarity. To be certain your figures and tables have aesthetic appeal, heed these practices: Do not crowd a table or figure, neither within itself nor within your text; give it room to breathe.

How do you make a perfect table? ›

Column and row headings
  1. Writing the headings. Tables are created using vertical columns and horizontal rows. ...
  2. Formatting and alignment. Align row headings on the left in the first column. ...
  3. Justify using a table. ...
  4. Stick to the essential information. ...
  5. Use notes. ...
  6. Use in-text references. ...
  7. Be consistent. ...
  8. Don't make it too long.

What is the best mapping package in R? ›

ggmap. The ggmap package is the most exciting R mapping tool in a long time! You might be able to get better looking maps at some resolutions by using shapefiles and rasters from naturalearthdata.com but ggmap will get you 95% of the way there with only 5% of the work!

How do I add a table in RStudio? ›

In R, these tables can be created using table() along with some of its variations. To use table(), simply add in the variables you want to tabulate separated by a comma.

What is the difference between Dataframes and tables in R? ›

frame in R is similar to the data table which is used to create tabular data but data table provides a lot more features than the data frame so, generally, all prefer the data. table instead of the data. frame.

References

Top Articles
Weiss Schwarz Rarity Guide
Wisconsin Volleyball Team Leaked Actual Photos Uncensored
Hometown Pizza Sheridan Menu
Rubratings Tampa
Maria Dolores Franziska Kolowrat Krakowská
Koordinaten w43/b14 mit Umrechner in alle Koordinatensysteme
Ashlyn Peaks Bio
GAY (and stinky) DOGS [scat] by Entomb
Rubfinder
1TamilMV.prof: Exploring the latest in Tamil entertainment - Ninewall
Devourer Of Gods Resprite
What is a basic financial statement?
Troy Athens Cheer Weebly
Nitti Sanitation Holiday Schedule
Chic Lash Boutique Highland Village
The Cure Average Setlist
U Arizona Phonebook
Ruben van Bommel: diepgang en doelgerichtheid als wapens, maar (nog) te weinig rendement
Ratchet & Clank Future: Tools of Destruction
Busted Newspaper Fauquier County Va
18889183540
Daytonaskipthegames
Mc Donald's Bruck - Fast-Food-Restaurant
Sunset Time November 5 2022
Uncovering The Mystery Behind Crazyjamjam Fanfix Leaked
Rs3 Ushabti
Gina Wilson Angle Addition Postulate
Miles City Montana Craigslist
Tracking every 2024 Trade Deadline deal
2021 Tesla Model 3 Standard Range Pl electric for sale - Portland, OR - craigslist
Mobile crane from the Netherlands, used mobile crane for sale from the Netherlands
Ancestors The Humankind Odyssey Wikia
Dubois County Barter Page
Siskiyou Co Craigslist
Seymour Johnson AFB | MilitaryINSTALLATIONS
The Legacy 3: The Tree of Might – Walkthrough
Scottsboro Daily Sentinel Obituaries
Mandy Rose - WWE News, Rumors, & Updates
Best Restaurant In Glendale Az
ENDOCRINOLOGY-PSR in Lewes, DE for Beebe Healthcare
9 oplossingen voor het laptoptouchpad dat niet werkt in Windows - TWCB (NL)
Craigslist Freeport Illinois
Craigslist Food And Beverage Jobs Chicago
Cuckold Gonewildaudio
8776725837
Why Are The French So Google Feud Answers
Southwest Airlines Departures Atlanta
Professors Helpers Abbreviation
Europa Universalis 4: Army Composition Guide
Legs Gifs
Maurices Thanks Crossword Clue
Qvc Com Blogs
Latest Posts
Article information

Author: Carlyn Walter

Last Updated:

Views: 6085

Rating: 5 / 5 (70 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Carlyn Walter

Birthday: 1996-01-03

Address: Suite 452 40815 Denyse Extensions, Sengermouth, OR 42374

Phone: +8501809515404

Job: Manufacturing Technician

Hobby: Table tennis, Archery, Vacation, Metal detecting, Yo-yoing, Crocheting, Creative writing

Introduction: My name is Carlyn Walter, I am a lively, glamorous, healthy, clean, powerful, calm, combative person who loves writing and wants to share my knowledge and understanding with you.