Search code examples
rgtsummary

Change character used for interaction term


Consider the following example:

library(gtsummary)

tbl_regression(lm(mpg~cyl*disp,mtcars))

Which results in:

enter image description here

Can I change the character for the interaction term to something like instead of *? If so, how?

I don't like the asterisk, I like the dot more.


Solution

  • You can use modify_table_body() to change the label. Below I use the unicode for a 'middle dot'.

        tbl_regression(lm(mpg~cyl*disp,mtcars)) %>% 
          modify_table_body(~ .x %>% 
                              dplyr::mutate(label = ifelse(label == "cyl * disp", 
    "cyl \U000B7 disp",  
    label )))
    

    enter image description here