arshad
arshad

Reputation: 437

R gtsummary package doesnt show the factor levels in the summary table

I have dataset like the following

> head(n2)
# A tibble: 6 x 4
  Pain  Redness Swelling Tiredness
  <fct> <chr>   <chr>    <chr>    
1 Yes   No      No       Yes      
2 No    No      No       No       
3 Yes   No      No       Yes      
4 Yes   No      Yes      Yes      
5 No    No      No       No       
6 No    No      No       No        

I am trying to make a summary table using gtsummary package. But in the summary table it is not showing the "Yes"/ "No" levels of Pain, Redness or Swelling variables, but rather it just shows the count of Yes of each columns. Can someone please help to show the "Yes"/ "No" levels in the table I am attaching the image of summary table created by gtsummary here.

Upvotes: 3

Views: 1873

Answers (1)

TarJae
TarJae

Reputation: 79194

We could use type argument of tbl_summary(). See here: https://www.danieldsjoberg.com/gtsummary/reference/tbl_summary.html under type argument:

library(dplyr)
library(gtsummary)

df %>% 
  mutate(across(everything(), ~factor(., levels = c("Yes", "No")))) %>% 
  tbl_summary(
    type = list(c(Pain, Redness, Swelling, Tiredness) ~ "categorical")
  ) 

enter image description here

Upvotes: 6

Related Questions