Playing with rstudio/gt R Package

Exploring the Movies Dataset — Movie Genre Overlappings, Ratings by Genre and Year

Ceshine Lee
Veritable
4 min readJan 22, 2019

--

Photo Credit

Tables can be an effective way of communicating data. Though not as powerful in telling stories as charts, by cramming a lot of numbers into a limited space, tables can provide readers with accurate and potentially useful information which readers can interpret in their own ways.

I’ve come across this new R package gt(Easily generate information-rich, publication-quality tables from R) and decided to give it a try.

With the gt package, anyone can make wonderful-looking tables using the R programming language. The gt philosophy: we can construct a wide variety of useful tables with a cohesive set of table parts. These include the table header, the stub, the stub head, the column labels, the table body, and the table footer.

Admittedly, the tables in my attempt might not be the optimal way of presentation. They serve as a demonstration of what gt can do, and maybe also helpful enough for analyst in constructing their stories about this dataset (The Movies Dataset on Kaggle).

Cheat Sheet

source

Source Code (Rendered RMarkdown)

You can find the full source code here:

Or this Github Repo:

The Github repo contains a Dockerfile and packrat configurations. Please refer to this previous post for more information:

(Unfortunately, I couldn’t installrstudio/gt in Kaggle Kernel. Otherwise, it would be a great place to host the rendered document.)

Genre Statistics

How to read the table: For example, Drama (the first row) has 13008 movies (the first column), and 2639 of them are also under Comedy, which is 20.3% of the 13008 movies.

The data in each section is symmetric, so I wasted almost half the data cells. A more clever way is to use one of the upper or lower triangles for raw counts, and the other for percentages.

Interesting features:

Making texts in the diagonal cells in the “Genre Overlappings” section bold and add underlines:

Displaying the numbers in the “Genre Overlappings(%)” section in percentage format:

Movie Ratings by Genre

Surprisingly, the distributions of ratings are quite similar across all genres. Maybe MovieLens has done some normalization on the ratings?

Movie Ratings by Genre and Year(Decade)

It appears the variances of ratings in the 1980s are lower than in the 1990s and the 2000s. (A boxplot or scatterplot might actually be more appropriate here.)

Adding footnotes:

I did not find any way to change the text style of the footnotes, though.

Conclusion

The rstudio/gt package is still in early development stage and hasn’t been released to CRAN yet. However, it already shows great promises and can be extremely helpful in creating beautiful tables in your reports and documents.

There are still plenty of the rstudio/gt features I did not cover in this post (e.g., row groups). I’m sure more awesome example usage of this package will soon emerge from the community. Stay tuned!

--

--

Ceshine Lee
Veritable

Data Geek. Maker. Researcher. Twitter: @ceshine_en