【问题标题】:how to change % so it reads horizontally rather than vertically on Gtsummary tables?如何更改 % 以便它在 Gsummary 表上水平而不是垂直读取?
【发布时间】:2022-12-10 14:36:31
【问题描述】:

我想重新定位我的表格,以便分别针对 ITN 用户和非用户组按级别给出 ITN 使用百分比,而不是每个级别的观察百分比。

基本上,我希望 % 在水平方向而不是垂直方向上加起来为 100

这是我用来制作表格的代码:

tbl_summary(pop.subtable1, by = ITN, missing = "no") %>%  
  modify_header(label = "Variable") %>% 
  modify_spanning_header(update = all_stat_cols() ~ "**ITN USE**") %>% 
  italicize_labels() %>% bold_labels() %>% 
  add_overall() %>% 
  modify_caption("Table 3. Bed Net Use Amongst Population Characteristics")

我想知道是否可以插入一行代码来手动执行此操作?

这是表格的样子: enter image description here

【问题讨论】:

  • tbl_summary 中有一个选项可以将百分比更改为 percent = "row",这是您要找的吗?
  • 是的,这正是我需要的,谢谢! :)

标签: r gtsummary


【解决方案1】:

根据@Mike 的评论,这是一个可重现的示例,因此其他人可以看到 percent = "column"(默认)和 percent = "row"tbl_summary() 之间的区别。

百分指示要返回的百分比类型。必须是“列”、“行”或“单元格”之一。默认为“列”。

library(gtsummary)
data(trial)

## default (column)
trial %>%
  select(trt, age, grade) %>%
  tbl_summary(
    by = trt,
    percent = "column",
    type = all_continuous() ~ "continuous2",
    missing = "no"
  ) 

## row
trial %>%
  select(trt, age, grade) %>%
  tbl_summary(
    by = trt,
    percent = "row",
    type = all_continuous() ~ "continuous2",
    missing = "no"
  ) 

【讨论】:

    猜你喜欢
    • 2017-09-01
    • 1970-01-01
    • 2016-11-21
    • 1970-01-01
    • 2017-10-18
    • 1970-01-01
    • 2017-12-18
    • 1970-01-01
    • 2019-02-27
    相关资源
    最近更新 更多