gtsummary

Modify the Reference Level gtsummary


Am trying to replace the _ in the regression table in gtsummary with Ref. My old code does not work as it used to be. I will appreciate assistance....

library(gtsummary)
mod1 <- glm(response ~ trt + age + grade, trial, family = binomial)

t1 <- tbl_regression(mod1, exponentiate = TRUE) 
 
# This code would do the trick but does not currently does not. Using `gtsummary_2.0.3`

t1 |>  
modify_table_styling(
  rows = reference_row %in% TRUE,
  missing_symbol = "Ref"
)

Solution

  • It looks like you need to specify the columns you want to apply this change to using the modify_table_styling(columns) argument. Example below!

    library(gtsummary)
    mod1 <- glm(response ~ trt + age + grade, trial, family = binomial)
    
    t1 <- tbl_regression(mod1, exponentiate = TRUE) 
    
    # This code would do the trick but does not currently does not. Using `gtsummary_2.0.3`
    
    t1 |>  
      modify_table_styling(
        columns = c(estimate, conf.low),
        rows = reference_row %in% TRUE,
        missing_symbol = "Ref"
      ) |> 
      bold_labels() |> 
      as_kable() # convert to kable to display on SO
    
    Characteristic OR 95% CI p-value
    Chemotherapy Treatment
    Drug A Ref Ref
    Drug B 1.13 0.60, 2.13 0.7
    Age 1.02 1.00, 1.04 0.10
    Grade
    I Ref Ref
    II 0.85 0.39, 1.85 0.7
    III 1.01 0.47, 2.15 >0.9

    Created on 2024-11-09 with reprex v2.1.1