Challenge 9: Formatting Nice Tables

For this Challenge you will explore how to generate nice looking tables for HTML documents, by applying the skills to your tables from Lab 8 and Lab 9.

There are many packages for generating tables, but I prefer the kable() function from the knitr package for simple tables and the gt() function from the DT package for more sophisticated tables.

I would recommend you think of tables no different from the visualizations you’ve been making. We want all aspects of our tables to be clear to the reader, so the comparisons we want them to make are straightforward. Tables are also a great avenue to display creativity! In fact, there is a yearly RStudio table contest, and here is a gallery of the award winning tables!

For simple tables

For more sophisticated tables

For interactive tables

1 Part 1 – Formatting Basic Tables

Use the kable() function from the kable package to create nice, basic HTML tables for every table in Lab 8.

Warning

Similar to axis labels in visualizations, every column name in a table should describe what it contains. For example, a column of n is less explanatory than Frequency of Babies.

2 Part 2 - Formatting Nicer Tables

Spice up at least one of your tables from Lab 9 using functions from the gt package.

Some ideas on how to “spice up” a table:

  • change the font and / or font size
  • add a title / subtitle to the table
  • add striping and / or cell borders to the table
  • create custom formatting of columns
Tip

Luckily, the gt package has an easy function for changing proportions to percentages (fmt_percent()) that you might want to use for your table from Question 2.