how to change orders of variables in gtsummary

library(tidyverse)
library(gtsummary)
penguins <- palmerpenguins::penguins %>%
  tidyr::drop_na()


mod1 <- lm(bill_length_mm ~ bill_depth_mm + sex,   data = penguins)

mod2 <- lm(body_mass_g ~ bill_length_mm + bill_depth_mm + sex,   data = penguins)



t1 <- tbl_regression(
  mod1, 
  intercept = TRUE,
  pvalue_fun = function(x) style_pvalue(x, digits = 3)
) %>% 
  add_glance_table(include = r.squared)



t2 <- tbl_regression(
  mod2, 
  intercept = TRUE,
  pvalue_fun = function(x) style_pvalue(x, digits = 3)
) %>% 
  add_glance_table(include = r.squared)



tbl_merge(
  tbls = list(t1, t2),
  tab_spanner = c("model 1", "model 2")
) 

want

Can the variable bill_length_mm move from the bottom line to the line above R squre is located?
Thank you for your help!

Can't you use change the table order in tbl_merge?

tbl_merge(
  tbls = list(t2, t1),
  tab_spanner = c("model 2", "model 1")
)

i found it

tbl_merge(
  tbls = list(t1, t2),
  tab_spanner = c("model 1", "model 2")
) %>% 
  modify_table_body(
    fun = ~ .x %>% arrange(variable)
  ) 

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.