I would like to change tbl_summary
header to "n = xx" instead of default "N = xx".
I understand that this could be modified by using modify_header
, like:
modify_header(update = all_stat_cols() ~ "**{level}**, N = {n}")
However, I cannot figure out how to make the N italicized, since N is already in the parenthesis to make it character.
CodePudding user response:
You can use any markdown syntax in the headers. In the example you provided, the double stars indicate bold. Use single stars to italicize the n. Example below!
library(gtsummary)
packageVersion("gtsummary")
trial %>%
select(age, grade, trt) %>%
tbl_summary(by = trt, missing = "no") %>%
modify_header(all_stat_cols() ~ "**{level}**, *n* = {n}")
To use markdown syntax in the body of a table, you can convert to gt and use the gt::fmt_markdown()
function.
library(gtsummary)
lm(mpg ~ factor(cyl) am, mtcars) %>%
tbl_regression() %>%
add_glance_table(
include = c(adj.r.squared, statistic, p.value),
label = list(statistic ~ "*F*",
adj.r.squared ~ "*Adjusted R\U00B2*",
p.value ~ "*p*")) %>%
as_gt() %>%
gt::fmt_markdown(columns = label)