I have the follow code to display multiple statistics. I need to display the confidence interval too, but the code display the CI in the wrong line, I would like to display in same line that mean(sd) are displayed.
library(gtsummary)
iris %>%
select(Sepal.Length, Sepal.Width,Species) %>%
tbl_summary(by = Species,
type = all_continuous() ~ "continuous2",
statistic = all_continuous() ~ c(
"{mean} ({sd})",
"{median} ({p25}, {p75})",
"{min}, {max}"
),
missing = "no", digits = everything() ~ 1) %>%
add_ci(include = all_continuous(),
statistic = all_continuous()~ "{conf.low}, {conf.high}")
Result table:

Table I want:

I am not sure if there is an argument within add_ci() to get what you need; but we can modify the output and shift the CI columns down.
library(gtsummary)
iris %>%
select(Sepal.Length, Sepal.Width,Species) %>%
tbl_summary(by = Species,
type = all_continuous() ~ "continuous2",
statistic = all_continuous() ~ c(
"{mean} ({sd})",
"{median} ({p25}, {p75})",
"{min}, {max}"
),
missing = "no", digits = everything() ~ 1) %>%
add_ci(include = all_continuous(),
statistic = all_continuous()~ "{conf.low}, {conf.high}") -> summary_table
for (x in paste0("ci_stat_", 1:3)) {
summary_table$table_body[[x]] <- dplyr::lag(summary_table$table_body[[x]])
}
summary_table

Created on 2024-03-08 with reprex v2.0.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With