How to add sectional variable header in gtsummary tbl_summary

18 Views Asked by At

I have a current table creating using the following code:

table1 <- 
  ptbl %>%
  dplyr::select( pt_gender.factor, pt_race.factor, pt_ethnicity.factor, education.factor, employed.factor,marital.factor,
                 home_smoker.factor,quit_support.factor,past7.factor) %>%
  tbl_summary(
    label = list(pt_gender.factor ~ "Gender",
                 pt_race.factor ~ "Race",
                 pt_ethnicity.factor ~ "Ethnicity",
                 education.factor ~ "Education",
                 employed.factor ~ "Employed",
                 marital.factor ~ "Marital Status",
                 home_smoker.factor ~ "Live with smoker",
                 quit_support.factor ~ "People around are very supportive of quitting smoking",
                 past7.factor ~ "In the past 7 days, did you smoke a cigarette (even a puff)?")) 

I am trying to add two sectional titles to my table, one is "Demographics", and the other one is "Smoking Habit".

I want my table like

Demographics Gender .... Race ... Ethnicity ... ...

Smoking Habit Live with smoker ... People around are very supportive of quitting smoking ..... enter image description here

Is there a function to do it?

0

There are 0 best solutions below