Use countrypops to create a gt table. Relabel all the table’s columns with the cols_label() function to improve its presentation. In this simple case we are supplying the name of the column on the left-hand side, and the label text on the right-hand side.
Using countrypops again to create a gt table, we label columns just as before but this time make the column labels bold through Markdown formatting (with the md() helper function). It’s possible here to use either a = or a ~ between the column name and the label text.
With the metro dataset, let’s create a small gt table with three columns. We’d like to provide column labels that have line breaks. For that, we can use <br> to indicate where the line breaks should be. We also need to use the md() helper function to signal to gt that this text should be interpreted as Markdown. Instead of calling md() on each of labels as before, we can more conveniently use the .fn argument and provide the bare function there (it will be applied to each label).
Using towny, we can create an interesting gt table. First, only certain columns are selected from the dataset, some filtering of rows is done, rows are sorted, and then only the first 10 rows are kept. When introduced to gt(), we apply some spanner column labels through two calls of tab_spanner() all the table’s columns. Below those spanners, we want to label the columns by the years of interest. Using cols_label() and select expressions on the left side of the formulas, we can easily relabel multiple columns with common label text. Note that we cannot use an = sign in any of the expressions within cols_label(); because the left-hand side is not a single column name, we must use formula syntax (i.e., with the ~).