Chapter 45 Data Tables

So far, we’ve spent a fair amount of time discussing how to make great exploratory and explanatory plots. However, plots are not the only ways to display data. Often, a table is a perfect approach to summarizing and displaying your data. In this lesson, we’ll discuss when to consider making a table instead of a plot, what to consider when making your table, and how to make tables in R and RMarkdown.

45.0.1 What are Data Tables?

Data tables are used to display data in a tabular format. They display the information in rows and columns. Good data tables do this in a meaningful and concise way. Similar to plots, tables can be exploratory (help you to better understand the data) or explanatory (beautifully and clearly display information in a table to others).

Exploratory vs. explanatory tables

In this lesson we will focus on characteristics of good plots and discuss how to take tables from exploratory to explanatory.

45.0.2 When to Make a Table

Just as for deciding what type of plot to make given the data you want to display, it’s important to consider what you’re trying to convey when making a table. Tables are effective when you want to display summary information about a dataset or when you want to display top results from an analysis.

45.0.2.1 Summarize dataset information

When you have an entire dataset, it’s often nice to have a table that summarizes important pieces of information. For example if you had a dataset with information on 32 different cars, you may be interested in the difference between cars in that dataset that have automatic vs. manual transmissions. Rather than go through and try to count them in this dataset, a table can do a nice job quickly summarizing and displaying this information for you. For example, you could display summarized information across a number of variables, such as how many of each type of car there are in your dataset (N), how fuel efficient the cars in each group are on average (mpg), the average weight of the cars in each group (weight), their average horsepower in each group (horsepower). This information can be easily displayed in a table. A table is better than a plot here because you’re trying to summarize information across a few different variables. A single plot that attempted to include all of this information would be less clear than this table. Similarly, four separate plots – one for each variable – would take up much more space. Thus, a table is the right approach here to display these data.

Sample summary tables

45.0.2.2 Summarize top results

Tables are also helpful when you want to display information about the top results from an analysis (i.e. the top 10 best-selling books, the business that had the highest sales last year, etc.).

For example, if you had information about 162,049 different flights that departed the Pacific Northwest in 2014 and wanted to know which destinations had the longest average delay for flights out of the Pacific Northwest, you could use a data table to display these results. At a glance from this table we can clearly see which airports had the longest delay in arrival time without .

Top results table

45.0.3 What to Consider When Making A Table

When making a table, it’s important to keep the ordering and spacing of your table in mind. It’s important to make sure everything is labeled appropriately and values within the table are displayed sensibly. More specifically, we’ll discuss a number of considerations to make when designing tables.

45.0.3.1 What to put in columns and what to put in rows

The human eye is much better at comparing values up and down rather than from left to right. Consider what comparisons you want viewers to be able to make easily when looking at the table. Then, put those in a column, rather than in a row.

Results vertically are better than comparing horizontally

45.0.3.2 The order of rows

Consider the data you’re putting in the table. If you’re displaying data over time, make sure the rows are in chronological order. If you’re displaying data about individuals, it’s likely best to order alphabetically by last name. Make sure that the order of rows helps viewers understand the table most quickly.

For example, if you are displaying a table about longest delay in flight time arrival, it’s likely best to order the table from longest delay in the first row to shorter delays at the bottom of the table.

Order rows logically

45.0.3.3 The order of columns

Put the most informative and important columns at the left and the less important columns at the right to assist viewers who read from left to right. (In languages where reading occurs from right to left, the ordering of columns should be reversed.)

Here, if we want viewers to understand which airports had the longest delays, it makes the most logical sense to start with the airport name at the left, rather than the mean arrival delay time, giving viewers some context about what they’re looking at before getting to the actual numbers.

Order columns with most important information at left

45.0.3.4 The number of rows and columns

Viewers should be able to figure out what the table is saying at a quick glance. If there are too many rows or too many columns, your data should most likely be a plot, not a table.

For example, if you are displaying information about arrests in each of the 50 US states, it may be better to consider plots, as it’s difficult to draw any conclusions about these data across 50 different rows. However, when we are only comparing across 5 rows, as in the case of our top results from the flights analysis, we can easily make comparisons across these five airports whose data are included in the table.

Limit the number of rows and columns

45.0.3.5 Labels

Labels on your columns and rows should be informative and clear. If talking about the price of diamonds, a bad column label would be “P” and a better column label would be “price.” An even better column label would be “price (USD).” This label is preferred because it provides viewers with the unit for the values in the table, conveying that these prices are all in US dollars. Viewers should be able to easily determine what information the table is displaying.

Below, the labels on the table at right are informative, whereas a viewer may not easily be able to determine what the column labels on the left (AN, AC, and MAD) mean.

Labels should be informative and concise

45.0.3.6 Significant digits

Including a lot of decimal places in a table is not helpful to viewers. Often, two significant digits is enough. You’ll want to always double check the values in your table to make sure they are displayed appropriately before finalizing a table.

Consider whether the appropriate number of digits for values in your table has been used

45.0.3.7 A good title or caption

Just like with good plots, good tables should have a title or caption that is clear and concise. It should tell viewers what they should determine from the data in the table.

Including a good title or caption is critical

45.0.3.8 The source of the data

Like with explanatory graphs, it’s important to include the source of the data used in your table at the bottom of the table when finalizing a table.

Always include the source of the data in your table

With an idea of how to make a great explanatory table, you’re ready to start practicing making your own in R.