- 3 Minutes Wednesdays
- Posts
- 3MW (Guidelines for better tables)
3MW (Guidelines for better tables)
Guten Tag!
Many greetings from Ulm, Germany. Today, we're going to create sexy tables. That's right. You read that correctly. Sexy tables.
Well, maybe "sexy" is a stretch. I'm not even sure what would classify a table as sexy (do not try to google that 🙈). But we're certainly going to create tables that are more aesthetically pleasing than this one.
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/876c4516-2b46-4984-9be5-b2c97afc97dd/stupid_table_screenshot.png)
Shamefully, I must admit that there was a time (not so long ago) that I totally created such monstrosities. Luckily, I've learned a couple of guidelines to improve tables. And today I'll share what I've learned.
Avoid vertical lines
This is the guideline that gives you the biggest bang for your buck. The above table uses waaaay to many grid lines. Without vertical lines, the table will look less cramped. Have a look for yourself.
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/b934a727-f336-4cd5-be7d-704097e8eb0c/image.png)
Bonus: I'm using the {gt} package to create this plot in R and it comes with a few sensible defaults. Texts are left-aligned and numbers are right-aligned. This ensures better readability compared to the all-centered approach in the original table.
Use better column names
Currently, the column names take up too much space. We can avoid that by combining columns. This can also avoid having to repeat partial names in multiple columns. Here's how that could look.
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/f652a478-0ead-4c8d-9a05-3bea6da4cac2/image.png)
Replace repetitive columns with grouped tables
The island column is somewhat repetitive. In cases like these, I'd rather remove the column. Instead, I would group the table using additional rows. I like to think that this comes with better readability.
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/50b973c8-d229-4ef9-88db-e6963f96e33b/image.png)
Remove missing numbers
Notice that our table has a lot of zeroes in it. For better readability, let us replace the zeroes with something more lightweight.
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/ff8ff299-51a0-4637-97a1-ab195a48d975/image.png)
Add summary lines
Now, this table looks already cleaner than what we started with. In this format, we could even add more information at little cost. For example, we could add a summary for each group. In this case, a summary could be as simple as a total count (over all years).
Though, I'm a bit worried that this table will get too long. That's why I've made it a little more compact (by reducing the row heights). Check it out.
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/fe19d7a8-e6b9-4bf7-b510-86f4616fb5ba/image.png)
Alright, I like to think that this table looks much better now. Of course, there's still a lot that could be customized. But that's a story for another time.
Recommended Resources
The {gt} package: All tables (except the first one) were produced with the amazing {gt} package. The documentation is pretty great because it contains many instructive examples. Find them here. Also, if {gt} is not enough for you, you can always extend its features with packages such as {gtExtras} and {gtsummary}.
{knitr} and the {kableExtra} package: The {knitr} package comes with another powerful engine to create tables with R. Personally, I use it whenever I need to create math-heavy tables for a LaTeX document. Technically, {gt} can do that too. But last time I checked, its math output wasn't as good. Also, you can enhance the features of knitr::kable() with the {kableExtra} package.
That's a wrap! As always, I'm happy to hear your feedback about this week's issue. Feel free to write me on Twitter or reply to this mail.
Enjoy the rest of your day!Albert
Reply