Let’s analyze some pizzaplace data with dplyr and then make a gt table. Here we are separately defining new column labels with cols_label() and then defining the units (to combine to those labels) through cols_units(). The default pattern for combination is "{1, {2}“} which is acceptable here.
The sza dataset has a wealth of information and here we’ll generate a smaller table that contains the average solar zenith angles at noon for different months and at different northern latitudes. The column labels are numbers representing the latitudes and it’s convenient to apply units of ‘degrees north’ to each of them with cols_units(). The extra thing we wanted to do here was to ensure that the units are placed directly after the column labels, and we do that with .units_pattern = "{1{2}“}. This append the units ("{2”}) right to the column label ("{1“}).
Taking a portion of the towny dataset, let’s use spanners to describe what’s in the columns and use only measurement units for the column labels. The columns labels that have to do with population and density information will be replaced with units defined in cols_units(). We’ll use a .units_pattern value of "{2“}, which means that only the units will be present (the "{1”}, representing the column label text, is omitted). Spanners added through several invocations of tab_spanner() will declare what the last four columns contain.