gt row group formatting (spanner?)

I am trying to format a table in gt with grouped rows, but so that the label is positioned to the left of the rows instead of above the rows. Is there a way to make spanner row labels (similar to spanner column labels, but for rows) or to re-position the row group label to the side?

Here is a mock-up of what I'd like it to look like.

Please bear with me, I'm quite new to R, but here is a reprex (I hope) of my relevant code.

flight_data <- flights %>%
  group_by(origin, carrier, month) %>%
  summarise(monthly_avg = mean(dep_delay)) %>%
  ungroup() %>%
  group_by(month, origin) %>%
  mutate(best_time_month = min(monthly_avg),
              worst_time_month = max(monthly_avg),
              best_worst = case_when(monthly_avg == best_time_month ~ "best_time",
                                                       monthly_avg == worst_time_month ~ "worst_time",
                                                       monthly_avg > best_time_month ~ "remove")) %>%
  filter(best_worst != "remove") %>%
  pivot_wider(names_from = best_worst, values_from = c(carrier, monthly_avg)) %>%
  select(-best_time_month, -worst_time_month) %>% 
  ungroup() %>%

flight_tbl <- gt(data = flight_data, rowname_col = "month") %>%
    label = "Best Delay Time",
    columns = vars(carrier_best_time, monthly_avg_best_time)) %>%
    label = "Worst Delay Time",
    columns = vars(carrier_worst_time, monthly_avg_worst_time)) %>%
  tab_stubhead(label = "Month") %>%
  cols_label(carrier_best_time = "Carrier",
             monthly_avg_best_time = "Mean delay (min)",
             carrier_worst_time = "Carrier",
             monthly_avg_worst_time = "Mean delay (min)") %>%
  tab_options(table_body.hlines.width = 0) %>%
  cols_align(align = "center")

This is something we missed when developing the stub label feature. However, it makes so much sense to (have the option to) have it appear the way it does in your mock up.

Would you be able to file this as an issue in the gt repo (at That way I can prioritize this work and you can be alerted on the progress of the feature.


Filed as issue #577, thanks!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.