59 lines
1.7 KiB
Text
59 lines
1.7 KiB
Text
---
|
|
title: "nicer tables"
|
|
format: docx
|
|
editor: visual
|
|
---
|
|
|
|
## Tables
|
|
|
|
```{r}
|
|
library(gtsummary)
|
|
library(dplyr)
|
|
packageVersion("gtsummary")
|
|
|
|
trial%>%
|
|
select(age, stage, grade)%>%
|
|
tbl_summary()%>%
|
|
modify_table_body(
|
|
~.x %>%
|
|
|
|
# add your variable
|
|
rbind(
|
|
tibble(
|
|
variable="Demographics",
|
|
var_type=NA,
|
|
var_label = "Demographics",
|
|
row_type="label",
|
|
label="Demographics",
|
|
stat_0= NA))%>% # expand the components of the tibble as needed if you have more columns
|
|
|
|
# can add another one
|
|
rbind(
|
|
tibble(
|
|
variable="Tumor characteristics",
|
|
var_type=NA,
|
|
var_label = "Tumor characteristics",
|
|
row_type="label",
|
|
label="Tumor characteristics",
|
|
stat_0= NA))%>%
|
|
|
|
# specify the position you want these in
|
|
|
|
arrange(factor(variable, levels=c("Demographics",
|
|
"age",
|
|
"Tumor characteristics",
|
|
"stage",
|
|
"grade"))))%>%
|
|
|
|
# and you can then indent the actual variables
|
|
modify_column_indent(columns=label, rows=variable%in%c("age",
|
|
"stage",
|
|
"grade"))%>%
|
|
|
|
# and double indent their levels
|
|
modify_column_indent(columns=label, rows= (variable%in%c("stage",
|
|
"grade")
|
|
& row_type=="level"),
|
|
double_indent=T)
|
|
|
|
```
|