-
Notifications
You must be signed in to change notification settings - Fork 218
Description
Hello, and thank you for at very good package. One feature I miss is the ability to have 2 levels of column spanners. When reporting results from competing risks analysis you often want to report uni- and multivariable hazard ratios for both the event of interest and the competing risk side by side in the same table. Like this generated with excel:
When trying to achieve the same in R with gt() and table_spanner() the second argument overwrites the first however:
example <- tibble(predictors = c('Age', 'Gender', 'COPD'), eventofinterest_uni_hr = c('1.01 (1.00 – 1.02)', '0.81 (0.65 - 1.02)', '1.77 (1.40 - 2.24)'),
eventofinterest_uni_p = c(0.19, 0.07, 0.003), eventofinterest_multi_hr = c('1.01 (1.00 - 1.02)', '0.83 (0.66 - 1.06)', '1.55 (1.20 - 2.00)'),
eventofinterest_multi_p = c(0.2, 0.14, 0.0004), competing_uni_hr = c('1.04 (1.02 – 1.06)', '1.02 (0.68 – 1.54)', '1.39 (0.91 – 2.13)'),
competing_uni_p = c(0.007, 0.91,0.12), competing_multi_hr = c('1.04 (1.02 – 1.06)', '1.06 (0.70 – 1.61)', '1.41 (0.90 – 2.21)'),
competing_multi_p = c(0.0025, 0.77, 0.14))
example %>%
gt() %>%
cols_label(eventofinterest_uni_hr = 'Hazard Ratio',
eventofinterest_multi_hr = 'Hazard Ratio',
competing_uni_hr = 'Hazard Ratio',
competing_multi_hr = 'Hazard Ratio',
eventofinterest_uni_p = 'p-value',
eventofinterest_multi_p = 'p-value',
competing_uni_p= 'p-value',
competing_multi_p = 'p-value') %>%
tab_spanner(label= 'Event of Interest',
columns = vars(eventofinterest_uni_hr, eventofinterest_uni_p, eventofinterest_multi_hr, eventofinterest_multi_p)) %>%
tab_spanner(label= 'Competing Risk of Death', columns = vars(competing_uni_hr, competing_uni_p, competing_multi_hr, competing_multi_p)) %>%
tab_spanner(label = 'Univariable', columns = vars(eventofinterest_uni_hr, eventofinterest_uni_p, competing_uni_hr, competing_uni_p), gather = F) %>%
tab_spanner(label = 'Multivariable', columns = vars(eventofinterest_multi_hr, eventofinterest_multi_p, competing_multi_hr, competing_multi_p), gather = F)Would that be possible to implement in the future? I know I can use group_by() or the groupname_col- argument in gt() to get to tables on top of each other for the event of interest and the competing risk respectively. Side-by-side is however how most journals want these reported and I also think it gives a better overview of data.
Best regards
Martin Schønemann-Lund